Skip to content

Commit

Permalink
Filter to possible sys.path entries before trying to resolve a module.
Browse files Browse the repository at this point in the history
With a long sys.path (it's got 300 entries), this removes 94% of stat syscalls
from running mypy. With all the filesystem caching, that's only a small time savings,
though it will depend on your filesystem.
  • Loading branch information
dmj-openai committed Oct 24, 2024
1 parent 3420ef1 commit 3f45615
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mypy/modulefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,14 @@ 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
candidate_package_dirs = {
package_dir[0]
for component in (components[0], components[0] + "-stubs", components[0] + ".py")
for package_dir in self.find_lib_path_dirs(component, self.search_paths.package_path)
}
for pkg_dir in self.search_paths.package_path:
if pkg_dir not in candidate_package_dirs:
continue
stub_name = components[0] + "-stubs"
stub_dir = os_path_join(pkg_dir, stub_name)
if fscache.isdir(stub_dir):
Expand Down

0 comments on commit 3f45615

Please sign in to comment.