Skip to content

support for __all__ with from ... import * #10516

@jbrelwof

Description

@jbrelwof

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

I have modified mp_import_all(...) in py/runtime.c to support from ... import * filtering when __all__ = [...] is present. The modified version is at https://github.com/jbrelwof/circuitpython/blob/main/py/runtime.c. It passes a variety of tests to ensure that it filters as desired and mimics CPython behavior in some edge cases.

I'd like to create a PR for this, but I don't think it's completely ready yet. It is functional, but I haven't done any CircuitPython PRs yet and it's my first non-trivial foray into C-level modifications of the CircuitPython runtime. There are probably "better" ways to do some things (like iterating through the all array, debug output, ...??? ). I also need to figure out how/where to incorporate the tests (and possibly add a few more).

Basically, I'm looking for

  • things that could be improved in the mp_import_all(...) modifications
  • general pointers on best practices for core PRs
  • what needs to be added to turn this into a "good" PR (tests, ... ???)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions