◐ Shell
clean mode source ↗

Message 307935 - Python tracker

For documentation of this feature, I'd suggest adding a new subsection after https://docs.python.org/3/reference/datamodel.html#customizing-attribute-access (but at the same level), called "Customizing module attribute access".

That can then cover defining __getattr__ and __dir__ as module level functions, and also mention setting __class__ (which would be enough to close issue 27505 as well).

The new section should explicitly mention that these only affect lookups and modifications made using the attribute access syntax - directly accessing the module globals (whether by code within the module, or via a reference to the module's globals dict) is unaffected.