[Python-Dev] Second post: PEP 557, Data Classes (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Wed Nov 29 01:19:50 EST 2017
- Previous message (by thread): [Python-Dev] Second post: PEP 557, Data Classes
- Next message (by thread): [Python-Dev] Second post: PEP 557, Data Classes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 29 November 2017 at 04:31, Eric V. Smith <eric at trueblade.com> wrote:
On 11/28/17 7:02 AM, Nick Coghlan wrote:
So in the above example, you would have:
>>> B.fieldlayout is B True >>> C1.fieldlayout is B True >>> C2.fieldlayout is B True It would then be up to the dataclass decorator to set
_fieldlayout_
correctly, using the follow rules: 1. Use the just-defined class if the class defines any fields 2. Use the just-defined class if it inherits from multiple base classes that define fields and don't already share an MRO 3. Use a base class if that's either the only base class that defines fields, or if all other base classes that define fields are already in the MRO of that base class That seems like a lot of complication for a feature that will be rarely used. I'll give it some thought, especially the MI logic. I think what you're laying out is an optimization for "do the classes have identical fields, inherited through a common base class or classes", right?
It's a combination of that and "How do I get my own class to compare equal with a dataclass instance?".
However, having the dataclass methods return NotImplemented for mismatched types should be enough to enable interoperability, since it will leave the question up to the other type.
Cheers, Nick.
-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
- Previous message (by thread): [Python-Dev] Second post: PEP 557, Data Classes
- Next message (by thread): [Python-Dev] Second post: PEP 557, Data Classes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]