No "missing return" error in function declared "-> X" where X is Any due to missing import

Abierto
#5,001 6 comentarios 6 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
32/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python
Área
devtools

Línea de trabajo

Start with the reported reproducer and run mypy with --ignore-missing-imports to confirm that the missing return is not reported when the annotation resolves to Any. Trace how missing-import types affect return checking, then add or update a regression test showing the expected diagnostic and run the relevant mypy test suite.

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

Descripción

feature needs discussion priority-1-normal
input
import arbitrary_module

def f() -> arbitrary_module.MyType:
    x = 1
    y = 2

# reveal_type(arbitrary_module.MyType)
output
$ mypy test.py --ignore-missing-imports
$ echo $?
0
expected (?)
test.py:3: error: Missing return statement
explanation

I get why this is happening, just feels non-ideal to me.

The revealed type above is Any, and implicit return None matches Any so this is allowed. The case I'd like to prevent is the accidental omission of a return statement here (this example has been reduced from an actual production issue).

From an implementation perspective I guess I'd want the types generated from --ignore-missing-imports to be non-nullable, though this might be a big change.

I'm sure there's a duplicate of this issue but I was struggling to search for it :S

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.