[Python-Dev] What is the design purpose of metaclasses vs code generating decorators? (was Re: PEP 557: Data Classes) (original) (raw)
Tin Tvrtković tinchester at gmail.com
Fri Oct 13 15🔞29 EDT 2017
- Previous message (by thread): [Python-Dev] What is the design purpose of metaclasses vs code generating decorators? (was Re: PEP 557: Data Classes)
- Next message (by thread): [Python-Dev] What is the design purpose of metaclasses vs code generating decorators? (was Re: PEP 557: Data Classes)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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) Message-ID: <_ _CAP7+vJKBVuDqf09zTWDAuvQ-cCNM+cF82c22s2NJOj+A9k7kA 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 ( https://www.amazon.com/Putting-Metaclasses-Work-Ira-Forman/dp/0201433052) 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.) --Guido
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... URL: <http://mail.python.org/pipermail/python-dev/attachments/20171013/6abad200/attachment.html>
- Previous message (by thread): [Python-Dev] What is the design purpose of metaclasses vs code generating decorators? (was Re: PEP 557: Data Classes)
- Next message (by thread): [Python-Dev] What is the design purpose of metaclasses vs code generating decorators? (was Re: PEP 557: Data Classes)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]