python / python/mypy

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

Offen
#11,322 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug topic-daemon
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der Daemon-Aktualisierungslogik in update.py und den Testfällen in test-data/unit/fine-grained-modules.test, insbesondere testDeletePackage4, testDeletePackage5 und testDeletePackage6. Führe pytest mypy/test/testfinegrained.py -k testDeletePackage4 -n0 mit aktiviertem --namespace-packages aus und überprüfe anschließend, dass die drei Tests die Auflösung von p.a nach dem Löschen von init.py beibehalten und mit den erwarteten Diagnosen übereinstimmen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
tooling
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
48/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.