False positive for function that takes a `Callable` as a parameter and returns a `Tuple` of `Union`
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 42/100
Línea de trabajo
Comienza ejecutando el fragmento de Python proporcionado con mypy 0.812 y confirma el error en la llamada de desempaquetado. Rastrea la inferencia de variables de tipo para Callable, Tuple y Union; se considera terminado cuando el reproductor pasa la comprobación de tipos sin el falso positivo informado y la cobertura de regresión protege este comportamiento.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Bug Report
The following code
from typing import (
Callable,
TypeVar,
Union,
Tuple,
)
T = TypeVar("T")
def test(pred: Callable[[T], bool]) -> Tuple[Union[T, int]]:
return (1,)
def main(pred: Callable[[T], bool]) -> None:
(val,) = test(pred) # the error appears here
def f(x: int) -> bool:
return x > 1
main(f)
triggers the mypy error
Argument 1 to "test" has incompatible type "Callable[[T], bool]"; expected "Callable[[Union[T, int]], bool]"
at the line that I marked with a comment. I believe this is a bug as this correction makes no sense to me (of couse, I could be wrong).
I'm aware that this code is meaningless, but it's the simplest sample I was able to produce that causes the error.
From the tests that I've done it seems to depend both on the type variable being used and on the function test returning a Tuple[Union[...]]. So if I replace T with a regular type of if I return either Union[T, int] or Tuple[int] instead of Tuple[Union[T, int]] the error goes away. It also disappears by not upacking the the result of test(pred).
To Reproduce
Take the code above and check it with mypy. That's it.
Expected Behavior
No error triggered.
Actual Behavior
Mypy detects the error reported above.
Your Environment
- Mypy version used: 0.812
- Mypy command-line flags: --ignore-missing-imports --follow-imports=silent --show-column-numbers
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.9.2
- Operating system and version: Linux x64
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Merge medio
- 1 d 18 h
- PR fusionados (30 d)
- 54
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.
Más de python/mypy
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
bug topic-configuration topic-error-reporting
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Todos los issues de python/mypy
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
bancolombia/sentinel#23 ·
-
test md AbiertoCI
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100