fails to import module from source directory for sources without .py extension
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 20.6k
- Forks
- 3.3k
- Métriques de merge des PR
- Métriques de PR en attente
Description
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)
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Reproduisez le problème avec testdir/integration-tests/common.py et testdir/integration-tests/test1 sans extension, puis exécutez mypy depuis testdir. Suivez la manière dont mypy construit son chemin de recherche pour une source sans extension .py ; le travail est terminé lorsque l’import common est trouvé et que mypy se termine sans erreur, tandis que les cas avec .py et avec un autre répertoire de travail continuent de fonctionner.
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é
- Plutôt claire
- Accessibilité débutants
- 45/100