Description
Bug Report
#13768 results in no errors when running on obviously incorrect code when run from a parent of the file being processed, as sys.path
sometimes includes this directory even when not included in PATH, PYTHONPATH, or MYPYPATH. As far as I can tell, this is expected behavior on the part of the interpreter, though I haven't been able to locate the code that adds it:
The first entry in the module search path is the directory that contains the input script, if there is one. Otherwise, the first entry is the current directory, which is the case when executing the interactive shell, a -c command, or -m module.
https://docs.python.org/3/library/sys_path_init.html
Python 3.10 docs actually seem clearer:
As initialized upon program startup, the first item of this list, path[0], is the directory containing the script that was used to invoke the Python interpreter.
https://docs.python.org/3.10/library/sys.html#sys.path
To Reproduce
Run on the following snippet any time the sys.path includes a parent of the snippet's location.
def test() -> None:
test: int = ""
Expected Behavior
mypy should detect incompatible assignment types.
Actual Behavior
No errors detected.
Your Environment
Ubuntu 22.04 on WSL1 and Eclipse PyDev on Windows 10. Note that a plain Windows 10 environment does not reproduce.
- Mypy version used: 0.990
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini
(and other config files):
follow_imports = "silent"
warn_redundant_casts = true
warn_unused_ignores = true
warn_unreachable = true
warn_return_any = true
strict_equality = true
disallow_untyped_defs = true
disallow_incomplete_defs = true
- Python version used: 3.10.6, 3.10.8