fails to import module from source directory for sources without .py extension
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
To Reproduce
Given the files:
testdir/integration-tests/common.py
class CommonConfig:
pass
testdir/integration-tests/test1
#!/usr/bin/env python3
import common
assert __name__ == '__main__'
config = common.CommonConfig()
If I run mypy from testdir/ on integration-tests/test1, it fails to find the import common from the same directory:
$ mypy integration-tests/test1
integration-tests/test1:3: error: Cannot find implementation or library stub for module named "common" [import-not-found]
integration-tests/test1:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)
Expected Behavior
I expect mypy to be able to find the common module from the directory containing the source file, and thus to exit without errors:
$ mypy integration-tests/test1
IIUC, it should find the import, since the search path should include: "The directories containing the sources given on the command line"
Other notes
If I rename test1 to test1.py, it works as expected.
If I run mypy from testdir/integration-tests instead of from testdir (such that common.py is in the current working directory), it works as expected.
Environment
$ python3 --version
Python 3.10.12
$ mypy --version
mypy 1.19.1 (compiled: yes)
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
Reproduziere das Problem mit testdir/integration-tests/common.py und testdir/integration-tests/test1 ohne Dateierweiterung und führe anschließend mypy aus testdir aus. Verfolge, wie mypy seinen Suchpfad für eine Quelle ohne .py-Erweiterung erstellt; fertig ist die Aufgabe, wenn der Import common gefunden wird und mypy ohne Fehler beendet wird, während die Fälle mit .py und mit einem alternativen Arbeitsverzeichnis weiterhin funktionieren.
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
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100