mypy
mypy copied to clipboard
Files without extensions are able to be imported as Python files
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