Instance variables typed as `Callable` on the class body don't get assignment warnings when missing in `__slots__`
Offen
Dieses Issue hat noch niemand übernommen.
bug
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere das Beispiel im verlinkten mypy Playground und vergleiche die vorhandene Diagnose für self.a mit der fehlenden Diagnose für self.b. Verfolge den Einstiegspunkt der Zuweisungsprüfung für __slots__ und füge Regressionstestabdeckung hinzu, damit die Zuweisung mit dem Typ Callable die erwartete [misc]-Warnung erhält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 48/100