Mypy treating type of final class variable in dataclass as Any
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
from dataclasses import dataclass
from typing import ClassVar, Final, reveal_type
class Bar: pass
@dataclass
class Foo:
cv: ClassVar[Final[dict[type[Bar], Foo]]] = {}
reveal_type(Foo.cv)
$ mypy test.py
test.py:10: note: Revealed type is "Any"
Success: no issues found in 1 source file
The correct type of Foo.cv is builtins.dict[type[Bar], Foo].
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.14&gist=2fad4ef5fded90ecaeb0f1d1e59d882a
Expected Behavior
reveal_type should report the correct type for the class variable.
Actual Behavior
reveal_type showed incorrect type (Any).
Your Environment
- Fedora 44
python3-mypy-1.18.2-4.fc44.noarch(reproducible with Mypy 2.3.1)python3-3.14.6-1.fc44.x86_64- No config files used
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
Beginne mit dem minimalen Reproducer im Issue oder dessen mypy-play-Link und verfolge dann, wie die Verarbeitung von Dataclasses ClassVar[Final[...]] bei der Ausführung von reveal_type behandelt. Erledigt ist die Aufgabe, wenn mypy für Foo.cv dict[type[Bar], Foo] meldet und das Verhalten durch einen Regressionstest abgedeckt ist.
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
- Aktiv
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 68/100