[Python-Dev] What is the design purpose of metaclasses vs code generating decorators? (was Re: PEP 557: Data Classes)
tinchester at gmail.com
Fri Oct 13 15:18:29 EDT 2017
> Date: Fri, 13 Oct 2017 08:57:00 -0700
> From: Guido van Rossum <guido at python.org>
> To: Martin Teichmann <lkb.teichmann at gmail.com>
> Cc: Python-Dev <python-dev at python.org>
> Subject: Re: [Python-Dev] What is the design purpose of metaclasses vs
> code generating decorators? (was Re: PEP 557: Data Classes)
> CAP7+vJKBVuDqf09zTWDAuvQ-cCNM+cF82c22s2NJOj+A9k7_kA at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
> This is food for thought. I'll have to let it sink in a bit, but you may be
> on to something.
> Since the question was asked at some point, yes, metaclasses are much older
> than class decorators. At some point I found the book Putting Metaclasses
> to Work by Ira Forman and Scott Danforth (
> and translated the book's ideas from C++ to Python, except for the
> automatic merging of multiple inherited metaclasses.
> But in many cases class decorators are more useful.
> I do worry that things like your autoslots decorator example might be
> problematic because they create a new class, throwing away a lot of work
> that was already done. But perhaps the right way to address this would be
> to move the decision about the instance layout to a later phase? (Not sure
> if that makes sense though.)
Just FYI, recreating the class with slots runs into problems with regards
to PEP 3135 (New Super). In attrs we resort to black magic to update the
__class__ cell in existing methods. Being able to add slotness later would
be good, but not that useful for us since we have to support down to 2.7.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev