Skip to content
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

Filter to possible package paths before trying to resolve a module. #18038

Merged
merged 6 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 10 additions & 1 deletion mypy/modulefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,16 @@ def _find_module(self, id: str, use_typeshed: bool) -> ModuleSearchResult:
found_possible_third_party_missing_type_hints = False
need_installed_stubs = False
# Third-party stub/typed packages
for pkg_dir in self.search_paths.package_path:
candidate_package_dirs = {
package_dir[0]
for component in (components[0], components[0] + "-stubs")
for package_dir in self.find_lib_path_dirs(component, self.search_paths.package_path)
}
for pkg_dir in [os.path.normpath(p) for p in self.search_paths.package_path]:
if pkg_dir not in candidate_package_dirs:
if approved_stub_package_exists(id):
need_installed_stubs = True
continue
stub_name = components[0] + "-stubs"
stub_dir = os_path_join(pkg_dir, stub_name)
if fscache.isdir(stub_dir):
Expand Down
2 changes: 1 addition & 1 deletion mypy/test/testmodulefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def setUp(self) -> None:
self.fmc_nons = FindModuleCache(self.search_paths, fscache=None, options=options)

def path(self, *parts: str) -> str:
return os.path.join(self.package_dir, *parts)
return os.path.normpath(os.path.join(self.package_dir, *parts))

def test__packages_with_ns(self) -> None:
cases = [
Expand Down
Loading