[Python-Dev] Second post: PEP 557, Data Classes (original) (raw)

Eric V. Smith eric at trueblade.com
Tue Nov 28 02:41:54 EST 2017


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 (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.



More information about the Python-Dev mailing list