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-November/150873.html below:

[Python-Dev] Second post: PEP 557, Data Classes

[Python-Dev] Second post: PEP 557, Data ClassesEric V. Smith eric at trueblade.com
Mon Nov 27 05:56:29 EST 2017
On 11/27/2017 1:04 AM, Nick Coghlan wrote:
> 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.

And in this case you could also do:
astuple(point) == astuple(vector)

Eric.

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