Skip to content

Commit

Permalink
Fix search paths for -p
Browse files Browse the repository at this point in the history
`-p` is similar to `-m` except that it will recursively typecheck submodules.

Unfortunately the early module walk was being done with search paths that
did not benefit from site_packages for the selected python executable,

which resulted in some packages being typechecked fine with `-m`, but
rejected as `not found` by `-p`.

Fixes #9386
  • Loading branch information
hugues-aff committed Sep 3, 2020
1 parent 5906a5d commit d20fa8f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
from mypy import defaults
from mypy import state
from mypy import util
from mypy.modulefinder import BuildSource, FindModuleCache, mypy_path, SearchPaths
from mypy.modulefinder import (
BuildSource, FindModuleCache, SearchPaths,
get_site_packages_dirs, mypy_path
)
from mypy.find_sources import create_source_list, InvalidSourceList
from mypy.fscache import FileSystemCache
from mypy.errors import CompileError
Expand Down Expand Up @@ -921,7 +924,16 @@ def set_strict_flags() -> None:
# Set target.
if special_opts.modules + special_opts.packages:
options.build_type = BuildType.MODULE
search_paths = SearchPaths((os.getcwd(),), tuple(mypy_path() + options.mypy_path), (), ())
# NB: duplicated logic from compute_search_paths
if options.python_executable is None:
egg_dirs = [] # type: List[str]
site_packages = [] # type: List[str]
else:
egg_dirs, site_packages = get_site_packages_dirs(options.python_executable)
search_paths = SearchPaths((os.getcwd(),),
tuple(mypy_path() + options.mypy_path),
tuple(egg_dirs + site_packages),
())
targets = []
# TODO: use the same cache that the BuildManager will
cache = FindModuleCache(search_paths, fscache, options, special_opts.packages)
Expand Down

0 comments on commit d20fa8f

Please sign in to comment.