mypy sometimes emits fewer errors when running on multiple files at once
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
Hello there,
I am witnessing (rare) cases where mypy emits fewer errors when running on multiple files at the same time than when running on each file individually.
More specifically, I noticed that mypy can fail to report an error when an import for a submodule is missing a one file but present in another file.
I failed to find anything relevant in the documentation or in the existing issues, so I thought I'd let you know. Below is my attempt at a minimal reproducible example.
To Reproduce
(Since multiple files are needed, here is an archive with the reproduction case: repro.zip)
Given a module mymodule with nested modules a and b, and this file foo.py:
import mymodule.a
def blah() -> None:
mymodule.b.fn()
blah()
As expected, when called on foo.py, mypy emits an error:
$ mypy --cache-dir /dev/null foo.py
foo.py:5: error: Module has no attribute "b"
Found 1 error in 1 file (checked 1 source file)
yet if I add to mypy's command line a second file which does import mymodule.b, say bar.py:
import mymodule.b
then mypy does not emit the error any more, even though I would expect it to:
$ mypy --cache-dir /dev/null foo.py bar.py
Success: no issues found in 2 source files
Your Environment
I used mypy 0.991 on Ubuntu 22.04 with python 3.10.6; I can reproduce this behavior with master, as well as python 3.8, and older versions of mypy.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Entpacke repro.zip und führe die beiden Befehle aus dem Bericht mit foo.py und bar.py aus, um die unterschiedlichen Diagnosen zu reproduzieren. Verfolge, wie Importe von mymodule.a und mymodule.b behandelt werden, wenn Dateien gemeinsam geprüft werden, und stelle dann sicher, dass der Fehler wegen des fehlenden Attributs bei beiden Aufrufen weiterhin gemeldet wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100