python / python/mypy

Any is inferred with a certain combination of overloads and generics

Abierto
#17,331 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

bug
Lenguaje dominante
Python
Estrellas
20.6k
Forks
3.3k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

Bug Report

(I couldn't come up with a better title, please fix)

I've got a piece of code where the inferred type is sometimes Any when it shouldn't be, and the difference between getting Any and the correct result doesn't make sense so it looks like a mypy bug to me. I may be wrong though.

The background: I'm trying to refactor and fix the overloads for https://github.com/scrapy/scrapy/blob/2b9e32f1ca491340148e6a1918d1df70443823e6/scrapy/utils/defer.py#L360, I've simplified the overloads and ignored the "overlapping signatures" error per https://stackoverflow.com/questions/60222982/type-annotation-for-overloads-that-exclude-types-something-vs-everything-else but the inferred result of the function works fine only if the input coroutine doesn't return e.g. List[Any]. It doesn't seem to fall back to the second overload either, as that wouldn't result in Any too. Overall it doesn't look like something with my code but maybe I'm missing something.

To Reproduce

https://gist.github.com/mypy-play/29b3eb14ab12db21dc8f52594f40c392

Expected Behavior

I expect the revealed type to always be a Deferred with the same param as the coroutine result type and never Any.

Actual Behavior

It's Any when, it looks like, the argument type has Any in it.

Your Environment

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con la reproducción vinculada de mypy-play y el gist, comparando la resolución de sobrecargas y los tipos revelados cuando el resultado de la corrutina contiene Any frente a un tipo preciso. Comprueba el comportamiento con mypy 1.10.0 y Python 3.12; se considera terminado cuando el resultado revelado conserva de forma coherente el tipo de resultado de la corrutina en lugar de convertirse en Any.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
compilers, 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

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.