Callable type anntoation written apart of assignment causes false positive typecheck result.
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Merge medio
- 1 d 18 h
- PR fusionados (30 d)
- 54
Descripción
A bugreport, mypy version is 0.761, python version is 3.7.3
This is a case where expected incapatible types, because i declared that foo's input type is float, and attempting to call it with str, but typechecking passed successful.
from typing import Callable
def bar(x): return 5
foo : Callable[[float],int]
foo = bar
foo("test")
mypy this_file.py
Mypy's output:
Success: no issues found in 1 source file
A case with type annotation written with assignment wont give false positive result:
from typing import Callable
def bar(x): return 5
foo : Callable[[float],int] = bar
foo("test")
mypy this_file.py
Mypy's output:
this_file.py:7: error: Argument 1 has incompatible type "str"; expected "float"
Found 1 error in 1 file (checked 1 source file)
I wasnt found other cases excluding cases with Callable type.
For example with Tuples type anntoation written apart of assignment all working fine:
from typing import Tuple
foo : Tuple[str,int]
foo = (1,3)
mypy this_file.py
Mypy's output:
this_file.py:4: error: Incompatible types in assignment (expression has type "Tuple[int, int]", variable has type "Tuple[str, int]")
Found 1 error in 1 file (checked 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
Reproduce los dos ejemplos de Callable con mypy 0.761 y Python 3.7.3; después, compara la ruta separada de declaración y asignación con la forma combinada. Rastrea el manejo de Callable en el comprobador de tipos y añade una prueba de regresión que espere un error de tipo de argumento incompatible para el caso de declaración separada.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 45/100