Skip to content

mypy_path Doesn't Work With --package #6595

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

Closed
ben-e-whitney opened this issue Mar 27, 2019 · 1 comment
Closed

mypy_path Doesn't Work With --package #6595

ben-e-whitney opened this issue Mar 27, 2019 · 1 comment
Labels
bug mypy got something wrong

Comments

@ben-e-whitney
Copy link

This issue is occurring with Debian GNU/Linux 9.8 (stretch), Python 3.7.2, and mypy 0.680+dev.3cea8326d5fbc67030316ccc4addc4297af6daaa. Here is a script to reproduce it:

#!/bin/bash

CAT=$(which cat)

mkdir mypy_path_test
cd mypy_path_test

mkdir --parents packages/a
touch packages/a/__init__.py

git clone https://github.com/python/mypy.git
cd mypy
git submodule init
git submodule update
cd ..

python3 -m venv .virtualenv
source .virtualenv/bin/activate
pip3 install --upgrade ./mypy

echo "python version:" $(python3 --version)
echo "mypy version:" $(mypy --version)

echo ""
echo "MYPYPATH works:"
MYPYPATH=packages/ mypy --package a

echo ""
echo "mypy_path doesn't work:"
$CAT << EOF > mypy.ini
[mypy]
mypy_path = packages/
EOF
mypy --package a

Output (after the installation):

python version: Python 3.7.2
mypy version: mypy 0.680+dev.3cea8326d5fbc67030316ccc4addc4297af6daaa

MYPYPATH works:

mypy_path doesn't work:
Can't find package 'a'

mypy finds the package when MYPYPATH is given as an environment variable but not when mypy_path is given in mypy.ini. As best I can tell, here's what happens:

  1. main.main calls main.process_options
  2. main.process_options calls main.process_config_file
  3. finding that a --package argument has been given, main.process_options calls modulefinder.mypy_path
  4. modulefinder.mypy_path gets the path from MYPYPATH and main.process_options never uses options.mypy_path

I can remedy the problem with the following change:

@@ -781,7 +781,9 @@ def process_options(args: List[str],
     # Set target.
     if special_opts.modules + special_opts.packages:
         options.build_type = BuildType.MODULE
-        search_paths = SearchPaths((os.getcwd(),), tuple(mypy_path()), (), ())
+        search_paths = SearchPaths(
+            (os.getcwd(),), tuple(mypy_path() + options.mypy_path), (), ()
+        )
         targets = []
         # TODO: use the same cache that the BuildManager will
         cache = FindModuleCache(search_paths, fscache)

If this is not expected behavior and this change is all that's needed, I am happy to make a pull request.

@gvanrossum gvanrossum added the bug mypy got something wrong label Mar 27, 2019
@gvanrossum
Copy link
Member

That's an astute observation and a good analysis. I think a PR would be appreciated. Make sure to add a test case for the new behavior!

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