Title: Annotation for builtin max() function uses wrong comparison operator · Issue #6336 · python/typeshed · GitHub
Open Graph Title: Annotation for builtin max() function uses wrong comparison operator · Issue #6336 · python/typeshed
X Title: Annotation for builtin max() function uses wrong comparison operator · Issue #6336 · python/typeshed
Description: The stubs for max() use SupportsLessThanT but should use SupportsGreaterThanT instead. The CPython source uses Py_GT. Instrumenting calls to max() shows the '>' operator being invoked: class I(int): def __gt__(self, other): print(f'{self...
Open Graph Description: The stubs for max() use SupportsLessThanT but should use SupportsGreaterThanT instead. The CPython source uses Py_GT. Instrumenting calls to max() shows the '>' operator being invoked: class I(int)...
X Description: The stubs for max() use SupportsLessThanT but should use SupportsGreaterThanT instead. The CPython source uses Py_GT. Instrumenting calls to max() shows the '>' operator being invoked: c...
Opengraph URL: https://github.com/python/typeshed/issues/6336
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Annotation for builtin max() function uses wrong comparison operator","articleBody":"The stubs for [max()](https://github.com/python/typeshed/blob/fbb89f9fd54566e292a63b80cb32053bd6eb1bb4/stdlib/builtins.pyi#L1135) use `SupportsLessThanT` but should use `SupportsGreaterThanT` instead.\r\n\r\nThe [CPython source](https://github.com/python/cpython/blob/32959108f9c543e3cb9f2b68bbc782bddded6f42/Python/bltinmodule.c#L1837) uses `Py_GT`.\r\n\r\nInstrumenting calls to *max()* shows the '>' operator being invoked:\r\n\r\n```\r\nclass I(int):\r\n def __gt__(self, other):\r\n print(f'{self} > {other}')\r\n return int.__gt__(self, other)\r\n def __lt__(self, other):\r\n print(f'{self} \u003c {other}')\r\n return int.__Lt__(self, other)\r\n\r\n>>> largest = max(map(I, [10, 40, 20]))\r\n40 > 10\r\n20 > 40\r\n>>> largest\r\n40\r\n```\r\n\r\nA class that supplies only `__gt__` suffices for a call to *max()*:\r\n\r\n```\r\nclass ReverseInt:\r\n def __init__(self, x):\r\n self.x = x\r\n def __gt__(self, other):\r\n return self.x \u003c other.x\r\n def __repr__(self):\r\n return f'{type(self).__name__}({self.x!r})'\r\n \r\n>>> max(map(ReverseInt, [10, 40, 20]))\r\nReverseInt(10)\r\n```\r\n","author":{"url":"https://github.com/rhettinger","@type":"Person","name":"rhettinger"},"datePublished":"2021-11-18T16:46:35Z","url":"https://github.com/python/typeshed/issues/6336"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b61cf193-7f53-2548-0d58-6bbb69fc0278 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8C00:14F601:4ED3F:6756F:6B00B817 |
| html-safe-nonce | 8ed5e53ed81db103cdf15435f043f315a9c7b675d57fd3c2aee4b559619825b2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QzAwOjE0RjYwMTo0RUQzRjo2NzU2Rjo2QjAwQjgxNyIsInZpc2l0b3JfaWQiOiI2MzMxOTk3Nzk1ODI5OTg3MzUxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 54d9fc46b6c752a6195ad377d1bab6cba8699a0a161d22ca89338d37638a043c |
| hovercard-subject-tag | issue:1057571927 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/typeshed/6336/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a192ebaf05205f1e720f4ce48c99e518babd3d3d7c2ea024a176b4071d91c0e8/python/typeshed/issues/6336 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a192ebaf05205f1e720f4ce48c99e518babd3d3d7c2ea024a176b4071d91c0e8/python/typeshed/issues/6336 |
| og:image:alt | The stubs for max() use SupportsLessThanT but should use SupportsGreaterThanT instead. The CPython source uses Py_GT. Instrumenting calls to max() shows the '>' operator being invoked: class I(int)... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rhettinger |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1d07c25977adfc5ff6acb0a962a9bc168c07afbda6fef765f9761c350c2ae4a2 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typeshed git https://github.com/python/typeshed.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 31696383 |
| octolytics-dimension-repository_nwo | python/typeshed |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31696383 |
| octolytics-dimension-repository_network_root_nwo | python/typeshed |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5429cbfc6aca8c7b9a086a3c8f47400346f38cc9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width