From: Armin Ronacher Date: Mon, 20 May 2013 00:53:10 +0000 (+0100) Subject: Added an explanation for how with_metaclass works X-Git-Tag: 2.7~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=285c955921744873a3955091b09baf0c710ad58f;p=thirdparty%2Fjinja.git Added an explanation for how with_metaclass works --- diff --git a/jinja2/_compat.py b/jinja2/_compat.py index 5d4fba54..2a0e6ed8 100644 --- a/jinja2/_compat.py +++ b/jinja2/_compat.py @@ -82,6 +82,15 @@ except NameError: def with_metaclass(meta, *bases): + # This requires a bit of explanation: the basic idea is to make a + # dummy metaclass for one level of class instanciation 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 has the advantage over six.with_metaclass in that it does not + # introduce dummy classes into the final MRO. class __metaclass__(meta): __call__ = type.__call__ __init__ = type.__init__