Movatterモバイル変換


[0]ホーム

URL:


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

Eric V. Smitheric 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> <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:@dataclassclass B:     i: int@dataclassclass C1(B): pass@dataclassclass C2(B): passYou 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-Devmailing list

[8]ページ先頭

©2009-2025 Movatter.jp