Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mypy ignores all files when run in directory above target #14054

Closed
adebrecht661 opened this issue Nov 9, 2022 · 3 comments
Closed

Mypy ignores all files when run in directory above target #14054

adebrecht661 opened this issue Nov 9, 2022 · 3 comments
Labels
bug mypy got something wrong

Comments

@adebrecht661
Copy link

adebrecht661 commented Nov 9, 2022

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
@adebrecht661 adebrecht661 added the bug mypy got something wrong label Nov 9, 2022
@adebrecht661 adebrecht661 changed the title Mypy ignores all files when run in directory below target Mypy ignores all files when run in directory above target Nov 9, 2022
@najtin
Copy link

najtin commented Nov 10, 2022

I have the same issue. Poetry acts different if packages are added with poetry add or by specifying them in the pyproject.toml and running poetry install. The later seems to add the project to path, which breaks linting in vs-code and probably some automated setups as well. Here is a detailed version on how to reproduce the issue microsoft/vscode-python#20182 (comment)

@AlexWaygood
Copy link
Member

@JukkaL was this fixed by #14060?

@adebrecht661
Copy link
Author

adebrecht661 commented Nov 10, 2022

Fixed in at least one of my cases (Eclipse environment is harder to test). I saw #14042, but it wasn't clear that this was the same root cause, as I'm running on packages with -p rather than files (which I see was addressed in that thread shortly after I created this issue). Will close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants