Incorrect handling of `import from` namespace package that spans site-packages and the source tree
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Bug Report
The following command:
mypy --explicit-package-bases ns_package/sub_ns_package1/test.py
Resulted in
ns_package/sub_ns_package1/test.py:1: error: Module "ns_package" has no attribute "sub_ns_package2" [attr-defined]
Found 1 error in 1 file (checked 1 source file)
With the following setup:
Source code tree:
ns_package
sub_ns_package1
test.py
(note that there is no __init__.py)
site-packages tree (partial):
ns_package
sub_ns_package2
module.py
(same, no __init__.py)
test.py contents:
from ns_package import sub_ns_package2
While scratching my head I also found the following:
import sub_ns_package.ns_package2works.- it also works if the above import appears together with
from ns_package import sub_ns_package2
To Reproduce
See the above.
Expected Behavior
mypy should finish happily in the above example.
Actual Behavior
ns_package/sub_ns_package1/test.py:1: error: Module "ns_package" has no attribute "sub_ns_package2" [attr-defined]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.0.1
- Mypy command-line flags:
--explicit-package-bases(tried with or without it) ;--namespace-packages(tried with or without it) - Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.8.16
Potential Fix
I have very little knowledge about the codebase, but the following patch would make the problem go away. I'm not sure it's the right fix though.
https://github.com/python/mypy/commit/e69bbd2c82e60640171dd7e2653c010976ad4239
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 el informe con el árbol de namespace-package mostrado y mypy --explicit-package-bases ns_package/sub_ns_package1/test.py; después, inspecciona el commit referenciado e69bbd2c82e60640171dd7e2653c010976ad4239. Añade cobertura de regresión para el caso de source-tree/site-packages dividido y verifica que el comando finaliza sin el error attr-defined.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- devtools
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100