Not reporting any error when function returns bool type while expecting str type

Abierto
#9,194 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
38/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python
Área
devtools

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

feature

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.get is 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:

  1. vim integration (e.g. mypy --ignore-missing-imports --strict-equality)
  2. tox (e.g. mypy --ignore-missing-imports --package foo)

Note: I've tried also changing to --no-strict-equality and 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

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.

Más de python/mypy

Todos los issues de python/mypy

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.