-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Description
Currently max()
expects __gt__
, but this example indicates that it also works if only __lt__
is present:
class Lt:
def __init__(self, x):
self.x = x
def __repr__(self):
return f"Lt({self.x})"
def __lt__(self, other):
return self.x < other.x
class Gt:
def __init__(self, x):
self.x = x
def __repr__(self):
return f"Gt({self.x})"
def __gt__(self, other):
return self.x > other.x
print(max(Lt(2), Lt(5))) # Lt(5)
print(max(Lt(5), Lt(2))) # Lt(5)
print(max(Gt(2), Gt(5))) # Gt(5)
print(max(Gt(5), Gt(2))) # Gt(5)
I think that we should accept either method.
The signature of max()
was changed to expect __gt__
in #6342.
Metadata
Metadata
Assignees
Labels
No labels