diff options
author | Ben Davis <bendavsi78@gmail.com> | 2014-04-26 13:12:46 -0500 |
---|---|---|
committer | Ben Davis <bendavsi78@gmail.com> | 2014-04-26 13:12:46 -0500 |
commit | 1d38c96b575efb415961a991124525cdad3ef569 (patch) | |
tree | 75bb7a0583c4673f5185e4635f4f91668bc5b8ba | |
parent | 7d02a2180b5c0920cd997112b774658207f1e7b1 (diff) | |
download | six-1d38c96b575efb415961a991124525cdad3ef569.tar.gz |
Fixed #66: Replace the implementation of `six.with_metaclass` with the Flask one.
-rw-r--r-- | six.py | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -637,7 +637,21 @@ _add_doc(reraise, """Reraise an exception.""") def with_metaclass(meta, *bases): """Create a base class with a metaclass.""" - return meta("NewBase", bases, {}) + # 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.). + 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, {}) + def add_metaclass(metaclass): """Class decorator for creating a class with a metaclass.""" |