Eric Snow <[email protected]> added the comment:
There is a conversion. See builtin___build_class__ in Python/bltinmodule.c
(and the LOAD_BUILD_CLASS target in Python/ceval.c). Specifically, the
metaclass (e.g. the builtin type) is instantiated using the namespace from the
class definition. The metaclass copies that namespace into a new dict. So the
following two bits of code are equivalent:
# using a class definition
ns = OrderedDict()
class Meta(type):
def __prepare__(*args, **kwargs):
return ns
class Spam(metaclass=Meta):
a = 1
b = 2
ns.move_to_end('a')
# using the metaclass directly
ns = OrderedDict()
ns['a'] = 1
ns['b'] = 2
ns.move_to_end('a')
Spam = Meta('Spam', (object,), ns)
In both cases Spam.__dict__ will be a proxy for a new dict copied from ns.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue34320>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com