Infering return type as a union of all returns in type-checked functions
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
Feature
Note: This is different than #4409 and #6646 which aim to change what is considered "annotated" and which functions are type-checked in the first place.
Mypy currently only type-check a function if its considered "annotated", ie: all parameters are annotated, or the return type is present (required for methods w/o parameters). Whilst mypy obviously can't infer a return type if it doesn't type-check the content of a function, I feel like methods that are checked could have their return type inferred as a union of whatever mypy think the type of the returns are.
Here's a very simple example comparing mypy and pyright/pylance
(same result in CLI)
Pitch
The idea would be to reduce clutter, and reduce the risk of hiding a useful true return type behind a more vague type.
Maybe there's a performance concern for libraries? (mypy having to read more code instead of stopping at a return annotation) How much is it? How much does caching help?
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
No se nombran archivos de implementación ni pruebas. Empieza por rastrear cómo mypy decide si una función se comprueba en cuanto a tipos y cómo gestiona las anotaciones de retorno explícitas; después, compara ese comportamiento con el ejemplo del issue y los issues referenciados. Se considerará terminado cuando las funciones comprobadas infieran una unión de sus expresiones de retorno y se comprendan las implicaciones para el rendimiento y el almacenamiento en caché.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- compilers
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 30/100