A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2017-September/149383.html below:

[Python-Dev] PEP 557: Data Classes

[Python-Dev] PEP 557: Data ClassesSteven D'Aprano steve at pearwood.info
Fri Sep 8 14:38:06 EDT 2017
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.unit_price, self.quantity_on_hand) ==
> > (other.name, other.unit_price, other.quantity_on_hand)
> >       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.



-- 
Steve
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4