Skip to content
Myr

Merge pull request #1539 from mjhennig/with_metaclass

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Improve function with_metaclass()

authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parents ac12e36, b3767ae · Browse files · 1 file+4 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+4 added−13 removed

  • other:+4 added−13 removed

1 file+4 added−13 removed

modified:flask/_compat.py+4 added-13 removed
52 unmodified lines
53 return cls545556def with_metaclass(meta, *bases):57 """Create a base class with a metaclass."""58 # This requires a bit of explanation: the basic idea is to make a59 # dummy metaclass for one level of class instantiation that replaces59 # itself with the actual metaclass. Because of internal type checks60 # we also need to make sure that we downgrade the custom metaclass61 # for one level to something closer to type (that's why __call__ and62 # __init__ comes back from type etc.).63 #64 # This has the advantage over six.with_metaclass in that it does not65 # introduce dummy classes into the final MRO.66 class metaclass(meta):67 __call__ = type.__call__68 __init__ = type.__init__60 # itself with the actual metaclass.61 class metaclass(type):62 def __new__(cls, name, this_bases, d):70 if this_bases is None:71 return type.__new__(cls, name, (), d)63 return meta(name, bases, d)73 return metaclass('temporary_class', None, {})64 return type.__new__(metaclass, 'temporary_class', (), {})656667# Certain versions of pypy have a bug where clearing the exception stack68# breaks the __exit__ function in a very peculiar way. This is currently
20 unmodified lines