python / python/mypy

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

Ouverte
#11,322 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

bug topic-daemon
Langage dominant
Python
Étoiles
20.6k
Forks
3.3k
Merge moyen
1 j 18 h
PR mergées (30 j)
54

Description

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par la logique de mise à jour du daemon dans update.py et les cas de test dans test-data/unit/fine-grained-modules.test, en particulier testDeletePackage4, testDeletePackage5 et testDeletePackage6. Exécutez pytest mypy/test/testfinegrained.py -k testDeletePackage4 -n0 avec --namespace-packages activé, puis vérifiez que les trois tests conservent la résolution de p.a après la suppression de init.py et correspondent aux diagnostics attendus.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
tooling
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Clairement spécifiée
Accessibilité débutants
48/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.