(🐞) `type.__call__` not checked properly
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
class A:
def __init__(self, x: int):
print(x)
A.__call__("a") # no error
A("a") # Argument 1 to "A" has incompatible type "str"; expected "int" [arg-type]
The typing spec says:
At runtime, a call to a class’ constructor typically results in the invocation of three methods in the following order:
- The
__call__method of the metaclass (which is typically supplied by thetypeclass but can be overridden by a custom metaclass and which is responsible for calling the next two methods)
So mypy is checking that usages of the call syntax (()) are conforming to the constructor type, but the functionally identical call attribute __call__. This is against the spec, which specifies that type checkers should mirror the behavior that __call__ will invoke __new__ and __init__
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 por el tratamiento que hace mypy de las llamadas al constructor y de las llamadas mediante atributo a type.__call__, usando como reproducción el ejemplo del issue. Sigue cómo se comprueba A("a") frente a A.__call__("a"), y añade cobertura que demuestre que ambas formas hacen cumplir el tipo del argumento del constructor.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- devtools
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100