Message326356
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. |
|
Date |
User |
Action |
Args |
2018-09-25 14:26:59 | eric.snow | set | recipients:
+ eric.snow, rhettinger, methane, Rosuav, serhiy.storchaka, steve.dower |
2018-09-25 14:26:59 | eric.snow | set | messageid: <1537885619.21.0.545547206417.issue34320@psf.upfronthosting.co.za> |
2018-09-25 14:26:59 | eric.snow | link | issue34320 messages |
2018-09-25 14:26:59 | eric.snow | create | |
|