Fix crash on mypy imports when using --extension-pkg-allow-list=mypy #10524
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a crash that occurs when using
--extension-pkg-allow-list=mypy
with imports of mypy modules. The issue was caused by mypyc-compiled objects not having__dict__
attributes, which caused anAttributeError
during astroid's module inspection process.Problem
When running:
With
example.py
containing:Pylint would crash with:
This occurred because:
__dict__
on all objectsmember().__dict__
during module inspection inraw_building.py
AttributeError
propagated up and was re-raised as anAstroidError
, causing a crashSolution
Added specific handling for
AttributeError
related to missing__dict__
attributes in the_get_imported_module
method:AttributeError
occurs that mentions__dict__
, treat it like anAstroidBuildingError
import-error
message instead of crashingAttributeError
instances are still re-raised to maintain existing behaviorThe fix is minimal and surgical - it only handles the specific case of missing
__dict__
attributes while preserving all other error handling behavior.Testing
Added a functional test
import_mypy_extension.py
that:--extension-pkg-allow-list=mypy
import-error
message is generated instead of crashingFixes #10223.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.