python / python/mypy

Mypy daemon + `--namespace-packages` mishandles deletion of `__init__.py`

Abierto
#11,322 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

bug topic-daemon
Lenguaje dominante
Python
Estrellas
20.6k
Forks
3.3k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

Bug Report

Run mypy with --namespace-packages flag.

If daemon is initially run with

p/__init__.py
p/a.py

Then delete p/__init__.py
We expect p to become a namespace package and p.a to be resolvable still. This does not happen.

The issue exists within the daemon update logic (update.py).
If we initialize the daemon with only

p/a.py

things work ok.

Issue was discovered via #11259 and #9636 for context

To Reproduce

In test-data/unit/fine-grained-modules.test, add to the first line of the following tests testDeletePackage4, testDeletePackage5, and testDeletePackage6

# flags: --namespace-packages

Can run the test with

source .tox/py37/bin/activate
pytest mypy/test/testfinegrained.py -k testDeletePackage4 -n0

Expected Behavior

for testDeletePackage4

  main:3: error: Argument 1 to "f" has incompatible type "int"; expected "str...
  ==
  main:3: error: Argument 1 to "f" has incompatible type "int"; expected "str...
  ==                                            (diff)
  main:2: error: Cannot find implementation or library stub for module named "p.a" (diff)
  main:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports (diff)
  main:2: error: Cannot find implementation or library stub for module named "p" (diff)

Actual Behavior

for testDeletePackage4

  main:3: error: Argument 1 to "f" has incompatible type "int"; expected "str...
  ==
  main:2: error: Import of "p.a" ignored        (diff)
  main:2: note: (Using --follow-imports=error, module not passed on command line) (diff)
  ==                                            (diff)
  main:2: error: Cannot find implementation or library stub for module named "p.a" (diff)
  main:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports (diff)
  main:2: error: Cannot find implementation or library stub for module named "p" (diff)

Ideally when fixing this task - we should convert the three aformentioned tests to use --namespace-packages

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.

Línea de trabajo

Comienza con la lógica de actualización del daemon en update.py y los casos de prueba en test-data/unit/fine-grained-modules.test, especialmente testDeletePackage4, testDeletePackage5 y testDeletePackage6. Ejecuta pytest mypy/test/testfinegrained.py -k testDeletePackage4 -n0 con --namespace-packages habilitado y, después, verifica que las tres pruebas conserven la resolución de p.a tras eliminar init.py y coincidan con los diagnósticos esperados.

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

Evaluación

Stack tecnológico
python
Área
tooling
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
48/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.