We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The stubs for max() use SupportsLessThanT but should use SupportsGreaterThanT instead.
SupportsLessThanT
SupportsGreaterThanT
The CPython source uses Py_GT.
Py_GT
Instrumenting calls to max() shows the '>' operator being invoked:
class I(int): def __gt__(self, other): print(f'{self} > {other}') return int.__gt__(self, other) def __lt__(self, other): print(f'{self} < {other}') return int.__Lt__(self, other) >>> largest = max(map(I, [10, 40, 20])) 40 > 10 20 > 40 >>> largest 40
A class that supplies only __gt__ suffices for a call to max():
__gt__
class ReverseInt: def __init__(self, x): self.x = x def __gt__(self, other): return self.x < other.x def __repr__(self): return f'{type(self).__name__}({self.x!r})' >>> max(map(ReverseInt, [10, 40, 20])) ReverseInt(10)
The text was updated successfully, but these errors were encountered:
max() uses SupportsGreaterThanT
1f432f8
Add SupportsGreaterThan and SupportsGreaterThanT Closes: python#6336
2e1d7d1
c8ae584
max() uses SupportsGreaterThanT (#6342)
a6e3699
Add SupportsGreaterThan and SupportsGreaterThanT Closes: #6336 Co-authored-by: Jelle Zijlstra <[email protected]>
max()
Thanks for fixing this.
Sorry, something went wrong.
Successfully merging a pull request may close this issue.
The stubs for max() use
SupportsLessThanT
but should useSupportsGreaterThanT
instead.The CPython source uses
Py_GT
.Instrumenting calls to max() shows the '>' operator being invoked:
A class that supplies only
__gt__
suffices for a call to max():The text was updated successfully, but these errors were encountered: