This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.snow
Recipients Rosuav, eric.snow, methane, rhettinger, serhiy.storchaka, steve.dower
Date 2018-09-25.14:26:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1537885619.21.0.545547206417.issue34320@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-09-25 14:26:59eric.snowsetrecipients: + eric.snow, rhettinger, methane, Rosuav, serhiy.storchaka, steve.dower
2018-09-25 14:26:59eric.snowsetmessageid: <1537885619.21.0.545547206417.issue34320@psf.upfronthosting.co.za>
2018-09-25 14:26:59eric.snowlinkissue34320 messages
2018-09-25 14:26:59eric.snowcreate