Skip to content

mypy_path Doesn't Work With --package #6595

@ben-e-whitney

Description

@ben-e-whitney

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions