From 492f011624ab8e076c1389a7f611d7ac1a3a3830 Mon Sep 17 00:00:00 2001 From: Hugues Bruant Date: Mon, 31 Aug 2020 12:31:04 -0700 Subject: [PATCH] Fix search paths for `-p` `-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 --- mypy/main.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mypy/main.py b/mypy/main.py index 9416536f73b75..f52e32220f2e0 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -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 @@ -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)