Skip to content

Use fast path in modulefinder more often #17950

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
Oct 15, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ def __init__(
for module in CORE_BUILTIN_MODULES:
if options.use_builtins_fixtures:
continue
path = self.find_module_cache.find_module(module)
path = self.find_module_cache.find_module(module, fast_path=True)
if not isinstance(path, str):
raise CompileError(
[f"Failed to find builtin module {module}, perhaps typeshed is broken?"]
Expand Down Expand Up @@ -2725,7 +2725,9 @@ def exist_added_packages(suppressed: list[str], manager: BuildManager, options:

def find_module_simple(id: str, manager: BuildManager) -> str | None:
"""Find a filesystem path for module `id` or `None` if not found."""
x = find_module_with_reason(id, manager)
t0 = time.time()
x = manager.find_module_cache.find_module(id, fast_path=True)
manager.add_stats(find_module_time=time.time() - t0, find_module_calls=1)
if isinstance(x, ModuleNotFoundReason):
return None
return x
Expand All @@ -2734,7 +2736,7 @@ def find_module_simple(id: str, manager: BuildManager) -> str | None:
def find_module_with_reason(id: str, manager: BuildManager) -> ModuleSearchResult:
"""Find a filesystem path for module `id` or the reason it can't be found."""
t0 = time.time()
x = manager.find_module_cache.find_module(id)
x = manager.find_module_cache.find_module(id, fast_path=False)
manager.add_stats(find_module_time=time.time() - t0, find_module_calls=1)
return x

Expand Down
2 changes: 1 addition & 1 deletion mypy/modulefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def _find_module(self, id: str, use_typeshed: bool) -> ModuleSearchResult:
return ModuleNotFoundReason.NOT_FOUND

def find_modules_recursive(self, module: str) -> list[BuildSource]:
module_path = self.find_module(module)
module_path = self.find_module(module, fast_path=True)
if isinstance(module_path, ModuleNotFoundReason):
return []
sources = [BuildSource(module_path, module, None)]
Expand Down
Loading