[Python-Dev] PEP 557: Data Classes (original) (raw)
Ethan Furman ethan at stoneleaf.us
Fri Sep 8 15:01:01 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 ]
On 09/08/2017 11:38 AM, Steven D'Aprano wrote:
On Fri, Sep 08, 2017 at 10:37:12AM -0700, Nick Coghlan wrote:
def eq(self, other): if other.class is self.class: return (self.name, self.unitprice, self.quantityonhand) == (other.name, other.unitprice, other.quantityonhand) return NotImplemented My one technical question about the PEP relates to the use of an exact type check in the comparison methods, rather than "isinstance(other, self.class)". I haven't read the whole PEP in close detail, but that method stood out for me too. Only, unlike Nick, I don't think I agree with the decision. I'm also not convinced that we should be adding ordered comparisons (lt gt etc) by default, if these DataClasses are considered more like structs/records than tuples. The closest existing equivalent to a struct in the std lib (apart from namedtuple) is, I think, SimpleNamespace, and they are unorderable.
I'll split the difference. ;)
I agree with D'Aprano that an isinstance check should be used, but I disagree with him about the rich comparison methods -- please include them. I think unordered should only be the default when order is impossible, extremely difficult, or nonsensical.
--
Ethan
- 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 ]