py/runtime: Ignore AttributeError when looking up __all__. - #19613
Open
dpgeorge wants to merge 1 commit into
Open
py/runtime: Ignore AttributeError when looking up __all__.#19613dpgeorge wants to merge 1 commit into
dpgeorge wants to merge 1 commit into
Conversation
Commit 570744d introduced a regression when using `from foo import *`: if the module used `__getattr__` and raised an `AttributeError` when doing `__getattr__("__all__")` then that exception would be raised up to the caller of the import, rather than being ignored. This commit fixes that by protecting the lookup of "__all__". Tests are added which makes sure the behaviour matches CPython. Fixes issue micropython#19265. Signed-off-by: Damien George <damien@micropython.org>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #19613 +/- ##
==========================================
- Coverage 98.59% 98.55% -0.04%
==========================================
Files 182 182
Lines 23320 23320
Branches 5 5
==========================================
- Hits 22992 22984 -8
- Misses 327 335 +8
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Code size report: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Commit 570744d introduced a regression when using
from foo import *: if the module used__getattr__and raised anAttributeErrorwhen doing__getattr__("__all__")then that exception would be raised up to the caller of the import, rather than being ignored.This commit fixes that by protecting the lookup of "all". Tests are added which makes sure the behaviour matches CPython.
Fixes issue #19265.
Testing
Tests are added that run under CI.
Trade-offs and Alternatives
There is minor NLR overhead for the
mp_load_method_protected()call, but import-star is already a slow path so shouldn't have much of an impact.Generative AI
I did not use generative AI tools when creating this PR.