False positives when redefining property in subclass
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
I'm running mypy on the following code: (no additional arguments)
class Base:
def __init__(self, value):
self._value = value
@property
def value(self):
return self._value
class Sub(Base):
@Base.value.setter
def value(self, value):
self._value = value
And it reports:
inherited_property.py:10: error: "Callable[[Any], Any]" has no attribute "setter"
Line 10 is @Base.value.setter, so it seems to have a problem with referring to a property defined in a different class. Python itself has no problem with this though.
If the property has a setter in the base class, a slightly different error is reported:
class Base:
def __init__(self, value):
self._value = value
@property
def value(self):
return self._value
@value.setter
def value(self, value):
self._value = value
class Sub(Base):
@Base.value.setter
def value(self, value):
self._value = value
This results in mypy reporting:
inherited_property.py:14: error: overloaded function has no attribute "setter"
Again the error is reported on the @Base.value.setter line.
I'm using a mypy dev snapshot (0.650+) on Python 3.6.5.
I found the existing issue #220, but that is so generic that I figured it would make sense to open a new separate issue for tracking this specific use case.
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 le diagnosi segnalate con i due esempi Python, iniziando dalla gestione di @property e dei riferimenti ad attributi ereditati in mypy. Traccia il motivo per cui Base.value viene trattato come una funzione richiamabile o sovraccaricata, quindi aggiungi una copertura che mostri che i setter delle sottoclassi che usano @Base.value.setter vengono accettati senza errori.
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
- 45/100