Mypy doesn't object to `cached_property` methods that don't exist
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza reproduciendo el comportamiento en el mypy playground enlazado con Python 3.12. Después inspecciona el tratamiento especial de mypy para los tipos similares a property, centrándote en por qué cached_property acepta setter y deleter. Se considera terminado cuando mypy informa de errores para los métodos que no están presentes en cached_property, preservando al mismo tiempo el comportamiento válido de cached_property.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100