Author eric.snow
Recipients Rosuav, eric.snow, inada.naoki, rhettinger, serhiy.storchaka, steve.dower
Date 2018-09-25.14:26:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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

  # using the metaclass directly

  ns = OrderedDict()
  ns['a'] = 1
  ns['b'] = 2
  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:59eric.snowsetrecipients: + eric.snow, rhettinger, inada.naoki, Rosuav, serhiy.storchaka, steve.dower
2018-09-25 14:26:59eric.snowsetmessageid: <>
2018-09-25 14:26:59eric.snowlinkissue34320 messages
2018-09-25 14:26:59eric.snowcreate