From d9f5ffe912c5bcf86088c3af9a85fbef7841f53f Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sun, 29 Jun 2014 11:20:14 -0700 Subject: simplify with_metaclass implementation --- six.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/six.py b/six.py index d42ac04..781b9af 100644 --- a/six.py +++ b/six.py @@ -698,20 +698,13 @@ else: def with_metaclass(meta, *bases): """Create a base class with a metaclass.""" - # This requires a bit of explanation: the basic idea is to make a - # dummy metaclass for one level of class instantiation that replaces - # itself with the actual metaclass. Because of internal type checks - # we also need to make sure that we downgrade the custom metaclass - # for one level to something closer to type (that's why __call__ and - # __init__ comes back from type etc.). + # This requires a bit of explanation: the basic idea is to make a dummy + # metaclass for one level of class instantiation that replaces itself with + # the actual metaclass. class metaclass(meta): - __call__ = type.__call__ - __init__ = type.__init__ def __new__(cls, name, this_bases, d): - if this_bases is None: - return type.__new__(cls, name, (), d) return meta(name, bases, d) - return metaclass('temporary_class', None, {}) + return type.__new__(metaclass, 'temporary_class', (), {}) def add_metaclass(metaclass): -- cgit v1.2.1