[Python-Dev] Second post: PEP 557, Data Classes (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Mon Nov 27 01:04:08 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 27 November 2017 at 15:04, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
Nick Coghlan wrote:
Perhaps the check could be: (type(lhs) == type(rhs) or fields(lhs) == fields(rhs)) and all (individual fields match) I think the types should always have to match, or at least one should be a subclass of the other. Consider: @dataclass class Point3d: x: float y: float z: float @dataclass class Vector3d: x: float y: float z: float Points and vectors are different things, and they should never compare equal, even if they have the same field names and values.
And I guess if folks actually want more permissive structure-based matching, that's one of the features that collections.namedtuple offers that data classes don't.
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 ]