我知道在模块范围内使用 __all__
,但是我遇到了在类内部使用 __all__
的情况。例如在Python标准库中:
class re(metaclass=_DeprecatedType):
"""Wrapper namespace for re type aliases."""
__all__ = ['Pattern', 'Match']
Pattern = Pattern
Match = Match
__all__
在这个上下文中的作用是什么?
re
模块。您可能会被后续的sys.modules[re.__name__] = re
所困惑,但这是设置了sys.modules['typing.re']
,而不是sys.modules['re']
。实际的re
模块完全不受影响。 - user2357112