Mypy doesn't object to `cached_property` methods that don't exist
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
Mypy includes functools.cached_property on it's list of property-list types, but considers it to be too identical to property. It allows the use of cached_property.setter and cached_property.deleter without raising an error, despite the fact that neither of these are methods that exist on cached_property.
I discovered this while looking at permutations of property-like behavior for https://github.com/python/typeshed/pull/13276.
Actually, I realized just now that it can be anything from any of the property types. See the second playground link. [Edit: this part fixed by #19313]
To Reproduce
Playground link showing : https://mypy-play.net/?mypy=latest&python=3.12&gist=f5336c7a8df8f028a565bab576b74062
This one shows that mypy doesn't object to non-existent methods of property used as a decorator:
https://mypy-play.net/?mypy=latest&python=3.12&gist=d91764177a604ba5640a1fe741718f52 [Edit: this part fixed by #19313]
Expected Behavior
I expect mypy to generate errors for methods that don't exist in the stubs, even with the special-cased behavior.
Actual Behavior
No errors are generated.
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, das Verhalten im verknüpften mypy Playground mit Python 3.12 zu reproduzieren. Untersuche anschließend mypys Sonderbehandlung von property-ähnlichen Typen und konzentriere dich darauf, warum cached_property setter und deleter akzeptiert. Als erledigt gilt die Aufgabe, wenn mypy für Methoden, die in cached_property nicht vorhanden sind, Fehler meldet und gleichzeitig gültiges cached_property-Verhalten beibehält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100