Files without extensions are able to be imported as Python files
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
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
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 comportamento con file.py che importa l’altro file senza estensione, usando il comando mypy mostrato nell’issue, e confrontalo con CPython. Inizia con le regole documentate per la scoperta degli import nella sezione import di running_mypy; il lavoro è completato quando i file senza estensione non vengono analizzati come moduli Python e la diagnostica risultante corrisponde al comportamento previsto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100