diff options
author | Benjamin Peterson <benjamin@python.org> | 2014-06-29 11:20:14 -0700 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2014-06-29 11:20:14 -0700 |
commit | d9f5ffe912c5bcf86088c3af9a85fbef7841f53f (patch) | |
tree | fa2bf1e0eea7a18907f84fa8e31f391ef8a3f48c | |
parent | b2cb78a8a0a2da037e56d981e22450089240e6e4 (diff) | |
download | six-d9f5ffe912c5bcf86088c3af9a85fbef7841f53f.tar.gz |
simplify with_metaclass implementation
-rw-r--r-- | six.py | 15 |
1 files changed, 4 insertions, 11 deletions
@@ -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): |