[Python-Dev] PEP 557: Data Classes (original) (raw)
Martin Teichmann lkb.teichmann at gmail.com
Thu Oct 12 14:21:29 EDT 2017
- Previous message (by thread): [Python-Dev] PEP 557: Data Classes
- Next message (by thread): [Python-Dev] PEP 557: Data Classes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi list,
first, a big thanks to the authors of PEP 557! Great idea!
For me, the dataclasses were a typical example for inheritance, to be more precise, for metaclasses. I was astonished to see them implemented using decorators, and I was not the only one, citing Guido:
I think it would be useful to write 1-2 sentences about the problem with inheritance -- in that case you pretty much have to use a metaclass, and the use of a metaclass makes life harder for people who want to use their own metaclass (since metaclasses don't combine without some manual intervention).
Python is at a weird point here. At about every new release of Python, a new idea shows up that could be easily solved using metaclasses, yet every time we hesitate to use them, because of said necessary manual intervention for metaclass combination.
So I think we have two options now: We could deprecate metaclasses, going down routes like PEP 487's init_subclass. Unfortunately, for data classes init_subclass it is too late in the class creation process for it to influence the slots mechanism. A new_subclass, that acts earlier, could do the job, but to me that simply sounds like reinventing the wheel of metaclasses.
The other option would be to simply make metaclasses work properly. We would just have to define a way to automatically combine metaclasses. Guido once mention once (here: https://mail.python.org/pipermail/python-dev/2017-June/148501.html) that he left out automatic synthesis of combined metaclasses on purpose, but given that this seems to be a major problem, I think it is about time to overthink this decision.
So I propose to add such an automatic synthesis. My idea is that a metaclass author can define the or and ror methods for automatic metaclass synthesis. Then if a class C inherits from two classes A and B with metaclasses MetaA and MetaB, the metaclass would be MetaA | MetaB.
Greetings
Martin
- Previous message (by thread): [Python-Dev] PEP 557: Data Classes
- Next message (by thread): [Python-Dev] PEP 557: Data Classes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]