Mypy isn't discovering all modules in namespace packages with multiple __path__ components
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 45/100
Línea de trabajo
Empieza en mypy/modulefinder.py, alrededor de la línea indicada, y luego reproduce el problema con la jerarquía pkg_a/pkg_b y el comando MYPYPATH=pkg_b:pkg_a mypy --namespace-packages --strict -p foo. Se considera completado cuando el descubrimiento de fuentes incluye ambos componentes del paquete de espacio de nombres y la comprobación de tipos informa de errores de module1.py y module2.py.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Bug Report
It seems that mypy isn't considering all parts of namespace package paths, and is only checking the sources corresponding to the first path in its path.
Hopefully the example below clarifies it. I searched quite a bit in the bug tracker/docs, but didn't find anything describing my scenario, so apologies if it's a dupe!
To Reproduce
Consider the following hierarchy
./pkg_a
./pkg_a/foo
./pkg_a/foo/module1.py
./pkg_a/foo/py.typed
./pkg_b
./pkg_b/foo
./pkg_b/foo/py.typed
./pkg_b/foo/module2.py
foo.module1 and foo.module2 simply contain a bit of code to demonstrate mypy error detection:
$ cat ./pkg_a/foo/module1.py
trigger_mypy_error: str = 123
$ cat ./pkg_b/foo/module2.py
trigger_mypy_error: str = 123
Just as expected, we have a namespace package, both modules are imported without issues:
$ PYTHONPATH=pkg_b:pkg_a python3 -c 'import foo; print(foo.__path__); import foo.module1; import foo.module2'
_NamespacePath(['/project/for_mypy_bugtracker/pkg_b/foo', '/project/for_mypy_bugtracker/pkg_a/foo'])
Actual Behavior
When type checking, mypy only detects module2.py and misses module1.py:
$ MYPYPATH=pkg_b:pkg_a mypy --namespace-packages --strict -p foo
pkg_b/foo/module2.py:1: error: Incompatible types in assignment (expression has type "int", variable has type "str") [assignment]
trigger_mypy_error: str = 123
^~~
Found 1 error in 1 file (checked 2 source files)
Seems that the only sources detected are from pkg_b:
MYPYPATH=pkg_b:pkg_a mypy --namespace-packages -p foo -v 2>&1 | grep BuildSource
LOG: Found source: BuildSource(path='pkg_b/foo', module='foo', has_text=False, base_dir=None, followed=False)
LOG: Found source: BuildSource(path='pkg_b/foo/module2.py', module='foo.module2', has_text=False, base_dir=None, followed=False)
I dug a bit and I suspect it has something to do with this line
https://github.com/python/mypy/blob/1dd8e7fe654991b01bd80ef7f1f675d9e3910c3a/mypy/modulefinder.py#L559 -- the result of finding the module is just one path (pkg_b in this case), so it doesn't have a chance to explore pkg_a.
Expected Behavior
Mypy should detect both foo.module1 and foo.module2
Your Environment
- Mypy version used:
1.7.1 (latest) - Python version used:
3.10
- 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
-
link-check link-check:sphinx-theme
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
OpenHands/extensions#626 · 1 comentario ·
-
Change observation tooltip text Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
CSCfi/sd-search-api#39 ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100