Skip to content

Cache _is_setuptools_namespace results to avoid repetitive I/O #2705

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
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
1 change: 1 addition & 0 deletions astroid/interpreter/_import/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ def contribute_to_path(
)


@lru_cache(maxsize=1024)
def _is_setuptools_namespace(location: pathlib.Path) -> bool:
try:
with open(location / "__init__.py", "rb") as stream:
Expand Down
6 changes: 5 additions & 1 deletion astroid/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,10 @@ def clear_cache(self) -> None:
# pylint: disable=import-outside-toplevel
from astroid.brain.helpers import register_all_brains
from astroid.inference_tip import clear_inference_tip_cache
from astroid.interpreter._import.spec import _find_spec
from astroid.interpreter._import.spec import (
_find_spec,
_is_setuptools_namespace,
)
from astroid.interpreter.objectmodel import ObjectModel
from astroid.nodes._base_nodes import LookupMixIn
from astroid.nodes.scoped_nodes import ClassDef
Expand All @@ -462,6 +465,7 @@ def clear_cache(self) -> None:
ObjectModel.attributes,
ClassDef._metaclass_lookup_attribute,
_find_spec,
_is_setuptools_namespace,
):
lru_cache.cache_clear() # type: ignore[attr-defined]

Expand Down
Loading