overload with wrong return type is ignored
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
When one of the alternatives of an overload has a return type T which is a subtype of the return type of the annotation U but that the body of the function returns a type V which is a subtype of U but not T, no error is reported
To Reproduce
from typing import overload
@overload
def f(a: int) -> str:
...
# this is completely wrong
@overload
def f(a: str) -> bool:
...
def f(a: str | int) -> str | bool:
return "Hello"
reveal_type(f("some string"))
https://mypy-play.net/?mypy=latest&python=3.12&flags=strict&gist=83c5a353e087d8bbe03d542e7340b4b5
Expected Behavior
mypy should complain that the body of the function returns an str which is incompatible with type bool (overload 2)
More generally, for each overload signature, mypy should check that the body of the function typechecks with the overload signature.
Actual Behavior
mypy reports no error
main.py:16: note: Revealed type is "builtins.bool"
Success: no issues found in 1 source file
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 con el reproductor de Python mostrado en main.py y ejecútalo con la configuración estricta de mypy-play enlazada. Sigue cómo se comprueban las firmas de overload con respecto al tipo de retorno de la implementación. Se considera terminado cuando mypy informe del retorno str incompatible para overload 2 y la regresión esté cubierta por una prueba.
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
- 38/100