Not reporting any error when function returns bool type while expecting str type
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 38/100
Línea de trabajo
Reproduce la función reportada con mypy 0.782, Python 3.7.7 y las opciones indicadas --strict-equality y --ignore-missing-imports; después, compara los diagnósticos con el error esperado del tipo de retorno. Rastrea la ruta de comprobación de tipos para las expresiones de retorno y los tipos desconocidos; se considera terminado cuando el comportamiento se haya corregido o documentado claramente con una prueba de regresión.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Hi
I noticed a situation where I wasn't getting a type error from mypy when I would have expected to get one.
Below is the code I have. I purposefully set the return type to str because I wanted to see a mypy error, and specifically I expected the error to be that I had set the wrong return type (e.g. as the code is doing a comparison, which will thus return a bool type, I expected mypy to say the return type should be of type bool):
def is_dev() -> str:
return settings.get("environment") == "dev"
In that code snippet you'll see settings.get(...), which is a function that returns a string, and we compare that string against another string.
Note: as
settings.getis custom code, mypy knows nothing about what type is being returned.
My hypothesis is that because my specific example uses code that mypy can't identify the type for (i.e. settings.get()), mypy just goes ahead and ignores any other possible type check errors (such as me specifying the return type as str).
If that's expected of mypy then fine, but it just confused me.
I'm using mypy version 0.782 and Python version 3.7.7.
I'm running mypy in two places:
- vim integration (e.g.
mypy --ignore-missing-imports --strict-equality) - tox (e.g.
mypy --ignore-missing-imports --package foo)
Note: I've tried also changing to
--no-strict-equalityand it makes no difference.
Thank you for any guidance you can give me.
- 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 1/5 Menos de una hora Aptitud para principiantes 90/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
zostera/django-bootstrap4#894 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
use-agent-os/agent-os#3276 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
NousResearch/hermes-agent#117848 ·