Instance variables typed as `Callable` on the class body don't get assignment warnings when missing in `__slots__`
Aperta
Nessuno ha ancora preso questa issue.
bug
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug Report, To Reproduce, & Actual Behaviour
See mypy Playground:
from collections.abc import Callable
class A:
__slots__ = ()
a: int
b: Callable[[int], str]
def __init__(self, /) -> None:
self.a = 1 # E: Trying to assign name "a" that is not in "__slots__" of type "__main__.A" [misc]
self.b = lambda _: str(_) # No warning
Expected Behavior
from collections.abc import Callable
class A:
__slots__ = ()
a: int
b: Callable[[int], str]
def __init__(self, /) -> None:
self.a = 1 # E: Trying to assign name "a" that is not in "__slots__" of type "__main__.A" [misc]
self.b = lambda _: str(_) # E: Trying to assign name "b" that is not in "__slots__" of type "__main__.A" [misc]
Your Environment
- Mypy version used: (Occurs as far back as 1.0.0)
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.9, 3.12
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci l’esempio nel mypy Playground collegato e confronta la diagnostica esistente per self.a con la diagnostica mancante per self.b. Traccia il punto di ingresso del controllo delle assegnazioni di __slots__ e aggiungi una copertura di regressione affinché l’assegnazione tipizzata Callable riceva l’avviso [misc] previsto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 48/100