1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
__all__ = ["publicFun", "PublicClass", "dynamicFun"]
# Definitions below should always be imported by a star import
def publicFun():
return 1
class PublicClass:
def __init__(self):
self._val = 1
# If __all__ support is enabled, definitions below
# should not be imported by a star import
def unlistedFun():
return 0
class UnlistedClass:
def __init__(self):
self._val = 0
# Definitions below should be not be imported by a star import
# (they start with an underscore, and are not listed in __all__)
def _privateFun():
return -1
class _PrivateClass:
def __init__(self):
self._val = -1
# Test lazy loaded function, as used by extmod/asyncio:
# Works with a star import only if __all__ support is enabled
_attrs = {
"dynamicFun": "funcs",
}
def __getattr__(attr):
mod = _attrs.get(attr, None)
if mod is None:
raise AttributeError(attr)
value = getattr(__import__(mod, globals(), locals(), True, 1), attr)
globals()[attr] = value
return value
|