diff options
| author | Simon Charette <charette.s@gmail.com> | 2014-04-29 00:44:04 -0400 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2014-04-29 09:43:08 -0400 |
| commit | a2340ac6d6b7e31c7e97e8fdaf3e1d73e43b24ba (patch) | |
| tree | 9013ea2f6dbc76ed32ad75e20c3ff7bbca6f7818 /django/utils/six.py | |
| parent | 2df7238512ecb9c19922a288592f4edfac1df43f (diff) | |
Use the new implementation of `six.with_metaclass`.
No more `NewBase` horrors.
Thanks to bendavis78 for his work on merging this into six.
Diffstat (limited to 'django/utils/six.py')
| -rw-r--r-- | django/utils/six.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/django/utils/six.py b/django/utils/six.py index dd171aa42f..bf94a83000 100644 --- a/django/utils/six.py +++ b/django/utils/six.py @@ -628,7 +628,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.""" |
