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=mypywith imports of mypy modules. The issue was caused by mypyc-compiled objects not having__dict__attributes, which caused anAttributeErrorduring astroid's module inspection process.Problem
When running:
With
example.pycontaining:Pylint would crash with:
This occurred because:
__dict__on all objectsmember().__dict__during module inspection inraw_building.pyAttributeErrorpropagated up and was re-raised as anAstroidError, causing a crashSolution
Added specific handling for
AttributeErrorrelated to missing__dict__attributes in the_get_imported_modulemethod:AttributeErroroccurs that mentions__dict__, treat it like anAstroidBuildingErrorimport-errormessage instead of crashingAttributeErrorinstances 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.pythat:--extension-pkg-allow-list=mypyimport-errormessage 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.