property fail on fget, fset
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Please provide more information to help us understand the issue:
- Are you reporting a bug, or opening a feature request?
Bug - Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
class A():
@property
def a(self) -> float:
return 0.5
class B():
@property
def a(self) -> float:
return 1.5
class C(A, B):
is_a:bool = True
@property
def a(self) -> float:
if self.is_a:
return A.a.fget(self)
else:
return B.a.fget(self)
if __name__ == '__main__':
c = C()
assert c.a ==0.5
c.is_a = False
assert c.a == 1.5
- What is the actual behavior/output?
warning: Returning Any from function declared to return "float"
error: "Callable[[A], float]" has no attribute "fget"
warning: Returning Any from function declared to return "float"
error: "Callable[[B], float]" has no attribute "fget"
-
What is the behavior/output you expect?
mypy should pass -
What are the versions of mypy and Python you are using?
mypy 0.650
Python 3.6.5Do you see the same issue after installing mypy from Git master?
Yes -
What are the mypy flags you are using? (For example --strict-optional)
no flags. -
If mypy crashed with a traceback, please paste
the full traceback below.
(You can freely edit this text, please remove all the lines
you believe are unnecessary.)
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, mypy auf der minimalen Reproduktion im Issue auszuführen, und vergleiche die Behandlung des Property-Zugriffs über A.a.fget und B.a.fget. Verfolge den Typprüfpfad für Property-Deskriptoren und aufrufbare Attribute; abgeschlossen ist die Aufgabe, wenn das Beispiel mit den erwarteten float-Rückgabetypen erfolgreich durchläuft.
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
- 45/100