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

Stop detecting modules compiled by cffi as namespace packages #1777

Merged
merged 2 commits into from Sep 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog
Expand Up @@ -17,6 +17,10 @@ What's New in astroid 2.12.10?
==============================
Release date: TBA

* Fixed a crash when introspecting modules compiled by `cffi`.

Closes #1776
Closes PyCQA/pylint#7399


What's New in astroid 2.12.9?
Expand Down
8 changes: 7 additions & 1 deletion astroid/interpreter/_import/util.py
Expand Up @@ -49,7 +49,13 @@ def is_namespace(modname: str) -> bool:
# .pth files will be on sys.modules
# __spec__ is set inconsistently on PyPy so we can't really on the heuristic here
# See: https://foss.heptapod.net/pypy/pypy/-/issues/3736
return sys.modules[modname].__spec__ is None and not IS_PYPY
# Check first fragment of modname, e.g. "astroid", not "astroid.interpreter"
# because of cffi's behavior
# See: https://github.com/PyCQA/astroid/issues/1776
return (
sys.modules[processed_components[0]].__spec__ is None
and not IS_PYPY
)
except KeyError:
return False
except AttributeError:
Expand Down