Open grantjenks opened 3 years ago
I think the ideal here is:
def __eq__(self, that):
if not isinstance(that, type(self)):
return NotImplemented
return (
self.__slots__ == that.__slots__
and all(item == iota for item, iota in zip(self, that))
)
oh hai,
imo, the ‘ideal’ is far from ideal.
__slots__
that said, here's a quick attempt that would be closer to ‘ideal’, and lo and behold, it doesn't suffer from perceived formatting ‘problems’ either:
class C:
def __eq__(self, other):
if not isinstance(other, type(self)):
return NotImplemented
if self.__slots__ != other.__slots__:
return False
for x in self.__slots__:
if getattr(self, x) != getattr(other, x):
return False
return True
the ‘ideal’ solution would be to not write any code at all, and use attrs
instead to declaratively define attributes and whether they should be included in an an equality comparison.
This ticket is not a discussion of that __eq__
method, but of the formatting of specific lines by the black
tool.
which is way more subtle and complex than this ticket seems to imply; see https://github.com/psf/black/issues/2156#issuecomment-1027175601
I'm not thrilled with this diff: