mypy fails to report missing "private" __x attribute
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
Mypy doesn't seem to grok that self.__x in a subclass is different from self.__x in a superclass. It also doesn't seem to understand order of initialization.
- Are you reporting a bug, or opening a feature request?
bug
- Please insert below the code you are checking with mypy
class A:
def __init__(self, x: int) -> None:
self.__x = x # replace this with pass and mypy reports the error
class B(A):
def __init__(self) -> None:
A.__init__(self, self.__x)
B()
- What is the actual behavior/output?
$ mypy --strict tytest.py
Success: no issues found in 1 source file
$ python tytest.py
Traceback (most recent call last):
File "tytest.py", line 11, in <module>
B()
File "tytest.py", line 8, in __init__
A.__init__(self, self.__x)
AttributeError: 'B' object has no attribute '_B__x
- What is the behavior/output you expect?
mypy should report:
tytest.py:8: error: "B" has no attribute "__x
- What are the versions of mypy and Python you are using?
mypy 0.700
Do you see the same issue after installing mypy from Git master?
yes (mypy-0.770+dev.01ca4e062e38a9db8f462b9464fbbd5dd945a8cf)
- What are the mypy flags you are using? (For example --strict-optional)
--strict
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 ejecutando el ejemplo tytest.py reportado con mypy --strict y compara el código aceptado con el AttributeError de Python. Lee las rutas de comprobación de tipos para el manejo de nombres con doble guion bajo y la inicialización de instancias; después añade cobertura que distinga entre atributos privados de la subclase y de la superclase e informe del atributo que falta antes de que se ejecute el programa.
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
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Tranquilo
- Claridad
- Bien especificado
- Aptitud para principiantes
- 55/100