Python Tip #239 (of 365): When implementing __eq__, return NotImplemented for ob...
Trey Hunner 🐍 @treyhunner@mastodon.social
Python Tip #239 (of 365):
When implementing __eq__, return NotImplemented for objects you don't know how to work with.
Filling in __eq__ on yesterday's Version class (__lt__ would need the same check):
class Version:
... # self.parts is (major, minor, patch)
def __eq__(self, other):
if not isinstance(other, Version):
return NotImplemented
return self.parts == other.parts
🧵 (1/3)