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

Normalize paths before checking #13587

Closed
mgilson opened this issue Sep 1, 2022 · 2 comments
Closed

Normalize paths before checking #13587

mgilson opened this issue Sep 1, 2022 · 2 comments
Labels
bug mypy got something wrong

Comments

@mgilson
Copy link
Contributor

mgilson commented Sep 1, 2022

Bug Report

I'm running into some issues in some scripting where we have a local repository of stubs that generally sits in the repository at some path relative to the python code in the project. Our linting scripts might look something like:

MYPYPATH=${PWD}/../stubs

This seems to be causing some issues in

mypy/mypy/modulefinder.py

Lines 816 to 842 in 3c7e216

# Start with a MYPYPATH environment variable at the front of the mypy_path, if defined.
mypypath = mypy_path()
# Add a config-defined mypy path.
mypypath.extend(options.mypy_path)
# If provided, insert the caller-supplied extra module path to the
# beginning (highest priority) of the search path.
if alt_lib_path:
mypypath.insert(0, alt_lib_path)
sys_path, site_packages = get_search_dirs(options.python_executable)
# We only use site packages for this check
for site in site_packages:
assert site not in lib_path
if (
site in mypypath
or any(p.startswith(site + os.path.sep) for p in mypypath)
or (os.path.altsep and any(p.startswith(site + os.path.altsep) for p in mypypath))
):
print(f"{site} is in the MYPYPATH. Please remove it.", file=sys.stderr)
print(
"See https://mypy.readthedocs.io/en/stable/running_mypy.html"
"#how-mypy-handles-imports for more info",
file=sys.stderr,
)
sys.exit(1)

Would it be problematic to normalize the paths before doing the p.startswith(...) check?

To Reproduce

  1. Find a python file that you want to check by itself.
  2. change your working directory to be the same directory as the file to check
  3. Run something like MYPYPATH=${PWD}/../any_sibling_directory mypy file_to_check.py (edit as necessary if you don't use bash :)

Expected Behavior

I would expect mypy to be able to check this file without any problems.

Actual Behavior

mypy basically just says it won't check the file and exits (with a non-successful exit status)

Your Environment

  • Mypy version used: 0.971
  • Mypy command-line flags: reproduced with/without --strict
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: python3.8
  • Operating system and version: Linux (ubuntu 20.04)
@mgilson mgilson added the bug mypy got something wrong label Sep 1, 2022
@hauntsaninja
Copy link
Collaborator

0.971 just has a bad bug, see #13214

I fixed this in #13223 but mypy didn't end up making a patch release: #13089 (comment)

@hauntsaninja
Copy link
Collaborator

I recommend downgrading to 0.961 and waiting for 0.980 #13385 . Alternatively, you could use mypy master :-)

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

2 participants