Importing unstubbed submodules of stubbed modules with silent imports gives inconsistent errors

Abierto
#1,852 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

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

Línea de trabajo

Start by reproducing the three commands in the issue with mypy's silent-imports handling, then trace how import x.y differs from from x import y when x has a stub and y does not. Done means the inconsistent behavior is resolved and the incomplete-stub case produces the intended diagnostic consistently.

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

Descripción

bug needs discussion priority-1-normal topic-usability

In this example, the boto package has a stub, but the boto.foo module does not:

$ python3 -m mypy --py2 --silent-imports -c 'import boto.foo'
# no error
$ python3 -m mypy --py2 --silent-imports -c 'from boto import foo'
<string>:1: error: Module has no attribute 'foo'
$ python3 -m mypy --py2 --silent-imports -c 'import boto.foo; boto.foo'
<string>:1: error: "module" has no attribute "foo"
# in real code, this error is on line where boto.foo is used

As you can see, the behavior here is inconsistent. import boto.foo gives no error, but attempting to use boto.foo later in the program does give an error.

I think the correct behavior here is for import x.y with --silent-imports to be an error when x has a stub but y does not, because this feels conceptually similar to other cases of incomplete stubs. Otherwise, you'd be in danger of importing nonexistent submodules from packages you have full stubs for, with no way to lock that down. The only downside to this approach is it means you have to use a type ignore when the stubs are incomplete, but that's already the case most of the time.

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.