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>
23 lines
403 B
Python
23 lines
403 B
Python
__all__ = ('publicFun2', 'PublicClass2')
|
|
|
|
|
|
# Definitions below should always be imported by a star import
|
|
def publicFun2():
|
|
return 2
|
|
|
|
|
|
class PublicClass2:
|
|
def __init__(self):
|
|
self._val = 2
|
|
|
|
|
|
# If __all__ support is enabled, definitions below
|
|
# should not be imported by a star import
|
|
def unlistedFun2():
|
|
return 0
|
|
|
|
|
|
class UnlistedClass2:
|
|
def __init__(self):
|
|
self._val = 0
|