Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jbrelwof
Copy link

@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
Collaborator

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

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