Built-in classes, such as the module class, do not go through the usual mechanism of user-defined do * classes and, as such, do not use metaclass.__prepare__ , PEP 520 does not apply to them, so the guarantees that it can distribute cannot be applied here.
Currently, the ordering of the module namespace is preserved due to the fact that the dictionary ordered by order, like the dictionary itself, is considered as an implementation detail.
* User classes first go through build_class (the LOAD_BUILD_CLASS function of the bytecode is loaded when you dis the class statement) in bltinmodule.c . This is the only place where __prepare__ is called (which returns a PyDict_New from type_prepare if a custom meta with __prepare__ not defined).
Jim fasarakis hilliard
source share