Files without extensions are able to be imported as Python files
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Repro
In file.py:
import other
In other (no file extension):
#!/bin/sh
echo syntax error
Running:
$ mypy file.py
other:3: error: invalid syntax [syntax]
Found 1 error in 1 file (errors prevented further checking)
When running in CPython, you get this:
$ python file.py
Traceback (most recent call last):
File "file.py", line 1, in <module>
import other
ModuleNotFoundError: No module named 'other'
So I would expect Mypy to return either a "module not found" error or a "this is not a python file" error instead actually parsing other as a Python file. From reading the docs it would seem that the other module should only be importable from other.py[i] or other/__init__.py[i], but not a file called other.
I found this while running Mypy on beartype which has shell files called pytest and sphinx in the root directory, which causes Mypy to import the shell scripts if pytest or sphinx is not installed.
Environment
$ mypy --version
mypy 0.991 (compiled: yes)
$ python --version
Python 3.10.9
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 Verhalten mit file.py, das die andere Datei ohne Erweiterung importiert, verwende den im Issue gezeigten mypy-Befehl und vergleiche es mit CPython. Beginne mit den dokumentierten Regeln zur Import-Erkennung im Import-Abschnitt von running_mypy; fertig ist es, wenn Dateien ohne Erweiterung nicht als Python-Module geparst werden und die resultierende Diagnose dem beabsichtigten Verhalten entspricht.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100