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

Fix setuptools>=64 import hooks #1752

Merged
merged 9 commits into from
Feb 5, 2023
17 changes: 12 additions & 5 deletions astroid/interpreter/_import/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class ModuleType(enum.Enum):
# Finders created by setuptools editable installs
"_EditableFinder": ModuleType.PY_SOURCE,
"_EditableNamespaceFinder": ModuleType.PY_NAMESPACE,
# Finders create by six
"_SixMetaPathImporter": ModuleType.PY_SOURCE,
}


Expand Down Expand Up @@ -382,12 +384,17 @@ def _find_spec_with_path(
# Support for custom finders
for meta_finder in sys.meta_path:
# See if we support the customer import hook of the meta_finder
try:
meta_finder_name: str = meta_finder.__name__ # type: ignore[attr-defined]
except AttributeError:
continue
meta_finder_name = meta_finder.__class__.__name__
if meta_finder_name not in _MetaPathFinderModuleTypes:
continue
# Setuptools>62 creates its EditableFinders dynamically and have
# "type" as their __clas__.__name__. We check __name__ as well
DanielNoord marked this conversation as resolved.
Show resolved Hide resolved
# to see if we can support the finder.
try:
meta_finder_name = meta_finder.__name__
except AttributeError:
continue
if meta_finder_name not in _MetaPathFinderModuleTypes:
continue

module_type = _MetaPathFinderModuleTypes[meta_finder_name]

Expand Down