Skip to content

support for __all__ filtering with from ... import *#10518

Closed
jbrelwof wants to merge 1 commit intoadafruit:mainfrom
jbrelwof:feature/import__all__
Closed

support for __all__ filtering with from ... import *#10518
jbrelwof wants to merge 1 commit intoadafruit:mainfrom
jbrelwof:feature/import__all__

Conversation

@jbrelwof
Copy link
Copy Markdown

@jbrelwof jbrelwof commented Jul 28, 2025

Circuitpython does not support filtering from someModule import * when someModule contains __all__ = ['symbol1', 'symbol2', ...]. This results in importing more symbols than intended, which can cause a little wasted memory (entries in the globals() in the scope containing from someModule import * ) and differs from CPython in ways that can introduce subtle bugs (primarily through unexpected replacement of existing symbols).

This includes an enhanced mp_import_all(...) in py/runtime.c to support from ... import * filtering when __all__ = [...] is present.

I have basic tests (which it passes) for the following:

  • import is actually filtered (non-_private symbols not contained in __all__ are not imported)
  • values of type other than string in __all__ will throw TypeError
  • undefined entries in __all__ (i.e. __all__ = ['hello','world'] where world is undefined) will throw AttributeError

but I'm not sure where/how to add them so they become part of the CircuitPython CI testing pipeline

I also have a few things that I got "working" through trial and error which might have more efficient / recognizable patterns available. For example:

  • iterating values in __all__
  • getting string value of __all__ for lookup key
  • optional (conditionally compiled) debug output
  • raising exceptions
  • ... ???

@dhalbert
Copy link
Copy Markdown
Collaborator

Since this is fixed by micropython#17331, we could wait for that. We will be merging from MicroPython when V1.26 comes out.

@dhalbert
Copy link
Copy Markdown
Collaborator

I'm going to close this since it will be fixed by some upstream code when we merge v1.26.

@dhalbert dhalbert closed this Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support for __all__ with from ... import *

2 participants