Skip to content
Myr

Merge pull request #471 from snoack/metaclass-improvement

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

Improve with_metaclass()

authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parents 6bf78bc, 743598d · Browse files · 1 file+5 added−14 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+5 added−14 removed

  • other:+5 added−14 removed

1 file+5 added−14 removed

modified:jinja2/_compat.py+5 added-14 removed
84 unmodified lines
85 return filename868788def with_metaclass(meta, *bases):89 """Create a base class with a metaclass."""90 # This requires a bit of explanation: the basic idea is to make a90 # dummy metaclass for one level of class instanciation that replaces91 # itself with the actual metaclass. Because of internal type checks92 # we also need to make sure that we downgrade the custom metaclass93 # for one level to something closer to type (that's why __call__ and94 # __init__ comes back from type etc.).95 #96 # This has the advantage over six.with_metaclass in that it does not97 # introduce dummy classes into the final MRO.98 class metaclass(meta):99 __call__ = type.__call__100 __init__ = type.__init__91 # dummy metaclass for one level of class instantiation that replaces92 # itself with the actual metaclass.93 class metaclass(type):94 def __new__(cls, name, this_bases, d):102 if this_bases is None:103 return type.__new__(cls, name, (), d)95 return meta(name, bases, d)105 return metaclass('temporary_class', None, {})96 return type.__new__(metaclass, 'temporary_class', (), {})979899try:100 from urllib.parse import quote_from_bytes as url_quote
2 unmodified lines