> > Date: Fri, 13 Oct 2017 08:57:00 -0700 > From: Guido van Rossum <gu...@python.org> > To: Martin Teichmann <lkb.teichm...@gmail.com> > Cc: Python-Dev <python-dev@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+a9k7...@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.
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com