Skip to content

py/runtime: Ignore AttributeError when looking up __all__. - #19613

Open
dpgeorge wants to merge 1 commit into
micropython:masterfrom
dpgeorge:py-runtime-fix-import-star-when-attr-er
Open

py/runtime: Ignore AttributeError when looking up __all__.#19613
dpgeorge wants to merge 1 commit into
micropython:masterfrom
dpgeorge:py-runtime-fix-import-star-when-attr-er

Conversation

@dpgeorge

Copy link
Copy Markdown
Member

Summary

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 #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.

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>
@dpgeorge dpgeorge added the py-core Relates to py/ directory in source label Aug 13, 2026
@dpgeorge dpgeorge added this to the release-1.29.0 milestone Aug 13, 2026
@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.55%. Comparing base (2aa3966) to head (a2053c0).
⚠️ Report is 3 commits behind head on master.

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              
Flag Coverage Δ
unix-coverage-32bit 98.56% <100.00%> (-0.04%) ⬇️
unix-coverage-64bit 98.52% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown

Code size report:

Reference:  esp32: Only disable hardware timers that were previously enabled. [1345700]
Comparison: py/runtime: Ignore AttributeError when looking up __all__. [merge of a2053c0]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
      esp32:    +0 +0.000% ESP32_GENERIC
     mimxrt:    +8 +0.002% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +2 +0.000% VIRT_RV32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

py-core Relates to py/ directory in source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant