Skip to content

Correct search order for installed packages #4878

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

Merged
merged 1 commit into from
Apr 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,10 @@ def _find_module(self, id: str, lib_path: Tuple[str, ...],
dir_chain = os.sep.join(components[:-1]) # e.g., 'foo/bar'
# TODO (ethanhs): refactor each path search to its own method with lru_cache

third_party_dirs = []
# We have two sets of folders so that we collect *all* stubs folders and
# put them in the front of the search path
third_party_inline_dirs = []
third_party_stubs_dirs = []
# Third-party stub/typed packages
for pkg_dir in _get_site_packages_dirs(python_executable):
stub_name = components[0] + '-stubs'
Expand All @@ -868,11 +871,12 @@ def _find_module(self, id: str, lib_path: Tuple[str, ...],
stub_components = [stub_name] + components[1:]
path = os.path.join(pkg_dir, *stub_components[:-1])
if fscache.isdir(path):
third_party_dirs.append(path)
third_party_stubs_dirs.append(path)
elif fscache.isfile(typed_file):
path = os.path.join(pkg_dir, dir_chain)
third_party_dirs.append(path)
candidate_base_dirs = self.find_lib_path_dirs(dir_chain, lib_path) + third_party_dirs
third_party_inline_dirs.append(path)
candidate_base_dirs = self.find_lib_path_dirs(dir_chain, lib_path) + \
third_party_stubs_dirs + third_party_inline_dirs

# If we're looking for a module like 'foo.bar.baz', then candidate_base_dirs now
# contains just the subdirectories 'foo/bar' that actually exist under the
Expand Down