On 11/27/2017 10:51 AM, Guido van Rossum wrote:
Following up on this subthread (inline below).

Didn't we at one point have something like

isinstance(other, self.__class__) and fields(other) == fields(self) and <all individual fields match>

(plus some optimization if the types are identical)?

That feels ideal, because it means you can subclass Point just to add some methods and it will stay comparable, but if you add fields it will always be unequal.

One thing this doesn't let you do is compare instances of two different subclasses of a base type:

@dataclass
class B:
    i: int

@dataclass
class C1(B): pass

@dataclass
class C2(B): pass

You can't compare C1(0) and C2(0), because neither one is an instance of the other's type. The test to get this case to work would be expensive: find the common ancestor, and then make sure no fields have been added since then. And I haven't thought through multiple inheritance.

I suggest we don't try to support this case.

Eric.

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to