Instance attributes specified in protocols should not be usable as class attributes in inheriting concrete classes
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
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
Inizia tracciando come mypy gestisce l’accesso agli attributi nelle sottoclassi concrete di Protocol; l’issue non indica alcun file sorgente né alcun test esistente. Aggiungi un test di regressione basato sull’esempio SomeProtocol/Class fornito e considera il lavoro completato quando gli accessi sia a x sia a y vengono rifiutati perché privi di ClassVar.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100