Instance attributes specified in protocols should not be usable as class attributes in inheriting concrete classes
Offen
Dieses Issue hat noch niemand übernommen.
feature
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Are you reporting a bug, or opening a feature request?
Bug
Minimal repro
from typing import Protocol
class SomeProtocol(Protocol):
y : int
x : int = 3
class Class(SomeProtocol):
pass
def test1() -> None:
y: int = Class.y # runtime error. mypy should catch it?
def test2() -> None:
x: int = Class.x # runs fine, but should probably be a mypy error?
What is the actual behavior/output?
mypy reports no errors.
What is the behavior/output you expect?
I would expect mypy to complain that Class does not have class attributes x nor y (they are not marked with ClassVar).
What are the versions of mypy and Python you are using?
mypy: 0.782
python: 3.8.3
What are the mypy flags you are using? (For example --strict-optional)
No flags
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 damit nachzuverfolgen, wie mypy den Attributzugriff auf konkrete Unterklassen von Protocol behandelt; im Issue wird weder eine Quelldatei noch ein bestehender Test genannt. Füge einen Regressionstest auf Grundlage des bereitgestellten SomeProtocol/Class-Beispiels hinzu und betrachte die Aufgabe als erledigt, wenn Zugriffe auf sowohl x als auch y abgelehnt werden, weil ihnen ClassVar fehlt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100