When the symbol `__all__` is defined in a module, `mp_import_all()` should import all listed symbols into the global environment, rather than relying on the underscore-is-private default. This is the standard in CPython. Each item is loaded in the same way as if it would be an explicit import statement, and will invoke the module's `__getattr__` function if needed. This provides a straightforward solution for fixing star import of modules using a dynamic loader, such as `extmod/asyncio` (see issue #7266). This improvement has been enabled at BASIC_FEATURES level, to avoid impacting devices with limited ressources, for which star import is of little use anyway. Additionally, detailled reporting of errors during `__all__` import has been implemented to match CPython, but this is only enabled when ERROR_REPORTING is set to MICROPY_ERROR_REPORTING_DETAILED. Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
21 lines
311 B
Python
21 lines
311 B
Python
# When __all__ is undefined, star import should only
|
|
# show objects that do not start with an underscore
|
|
|
|
|
|
def visibleFun():
|
|
return 42
|
|
|
|
|
|
class VisibleClass:
|
|
def __init__(self):
|
|
self._val = 42
|
|
|
|
|
|
def _hiddenFun():
|
|
return -1
|
|
|
|
|
|
class _HiddenClass:
|
|
def __init__(self):
|
|
self._val = -1
|