fails to import module from source directory for sources without .py extension
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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)
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci il problema con testdir/integration-tests/common.py e testdir/integration-tests/test1 senza estensione, quindi esegui mypy da testdir. Traccia come mypy costruisce il proprio percorso di ricerca per un file sorgente senza estensione .py; il lavoro è completato quando l’import common viene trovato e mypy termina senza errori, mentre i casi con .py e con una directory di lavoro alternativa continuano a funzionare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100