Title: False positive with `builtins.min(T, T)` if `T.__lt__` doesn't return a `builtins.bool` · Issue #12562 · python/typeshed · GitHub
Open Graph Title: False positive with `builtins.min(T, T)` if `T.__lt__` doesn't return a `builtins.bool` · Issue #12562 · python/typeshed
X Title: False positive with `builtins.min(T, T)` if `T.__lt__` doesn't return a `builtins.bool` · Issue #12562 · python/typeshed
Description: Since NumPy 2.1 all subtypes of numpy.number implement __lt__ that returns a numpy.bool (which isn't a builtins.bool), matching the runtime behavior (numpy/numpy#26942). But as was noticed in numpy/numpy#27251, the consequence of this is...
Open Graph Description: Since NumPy 2.1 all subtypes of numpy.number implement __lt__ that returns a numpy.bool (which isn't a builtins.bool), matching the runtime behavior (numpy/numpy#26942). But as was noticed in numpy...
X Description: Since NumPy 2.1 all subtypes of numpy.number implement __lt__ that returns a numpy.bool (which isn't a builtins.bool), matching the runtime behavior (numpy/numpy#26942). But as was noticed in n...
Opengraph URL: https://github.com/python/typeshed/issues/12562
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"False positive with `builtins.min(T, T)` if `T.__lt__` doesn't return a `builtins.bool`","articleBody":"Since NumPy 2.1 all subtypes of `numpy.number` implement `__lt__` that returns a `numpy.bool` (which isn't a `builtins.bool`), matching the runtime behavior (https://github.com/numpy/numpy/pull/26942).\r\n\r\nBut as was noticed in https://github.com/numpy/numpy/issues/27251, the consequence of this is that `builtins.min` with e.g. `numpy.int32` input is now rejected (tested with the latest mypy and pyright). \r\n\r\nSo at runtime we have\r\n\r\n```pycon\r\n>>> import numpy as np\r\n>>> np.__version__\r\n'2.1.0'\r\n>>> np.int32(8) \u003c np.int32(9)\r\nnp.True_\r\n>>> min(np.int32(8), np.int32(9))\r\nnp.int32(8)\r\n```\r\n\r\nBut mypy 1.11.1 rejects `min(np.int32(8), np.int32(9))` as:\r\n\r\n```\r\nerror: No overload variant of \"min\" matches argument types \"signedinteger[_32Bit]\", \"signedinteger[_32Bit]\" [call-overload]\r\n```\r\n\r\nSimilarly, Pyright 1.1.376 reports\r\n\r\n```\r\nerror: Argument of type \"int32\" cannot be assigned to parameter \"arg1\" of type \"SupportsRichComparisonT@min\" in function \"min\"\r\n Type \"int32\" is incompatible with type \"SupportsRichComparison\"\r\n Type \"int32\" is incompatible with type \"SupportsRichComparison\"\r\n \"signedinteger[_32Bit]\" is incompatible with protocol \"SupportsDunderLT[Any]\"\r\n \"__lt__\" is an incompatible type\r\n No overloaded function matches type \"(other: _T_contra@SupportsDunderLT, /) -> bool\"\r\n \"signedinteger[_32Bit]\" is incompatible with protocol \"SupportsDunderGT[Any]\"\r\n \"__gt__\" is an incompatible type\r\n No overloaded function matches type \"(other: _T_contra@SupportsDunderGT, /) -> bool\" (reportArgumentType)\r\n```\r\n\r\nand\r\n\r\n```\r\nerror: Argument of type \"int32\" cannot be assigned to parameter \"arg2\" of type \"SupportsRichComparisonT@min\" in function \"min\"\r\n Type \"int32\" is incompatible with type \"SupportsRichComparison\"\r\n Type \"int32\" is incompatible with type \"SupportsRichComparison\"\r\n \"signedinteger[_32Bit]\" is incompatible with protocol \"SupportsDunderLT[Any]\"\r\n \"__lt__\" is an incompatible type\r\n No overloaded function matches type \"(other: _T_contra@SupportsDunderLT, /) -> bool\"\r\n \"signedinteger[_32Bit]\" is incompatible with protocol \"SupportsDunderGT[Any]\"\r\n \"__gt__\" is an incompatible type\r\n No overloaded function matches type \"(other: _T_contra@SupportsDunderGT, /) -> bool\" (reportArgumentType)\r\n```","author":{"url":"https://github.com/jorenham","@type":"Person","name":"jorenham"},"datePublished":"2024-08-20T15:19:39Z","url":"https://github.com/python/typeshed/issues/12562"}
| 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:a7990aa0-18c3-770f-1da0-4c4ae1cbd31b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8378:23FDF9:2620751:341BF54:6B0043DF |
| html-safe-nonce | a0791a6a49724092811cb57f52c2daecaf0fca68a15e241c92ac4026c9f86d9d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Mzc4OjIzRkRGOToyNjIwNzUxOjM0MUJGNTQ6NkIwMDQzREYiLCJ2aXNpdG9yX2lkIjoiODg4NDM3MzU3NzEwMTQ5MzIxNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 226ad9954497b30dad578205a3c6a8a884edcf1420e55c60c29a0219a2cef317 |
| hovercard-subject-tag | issue:2475921930 |
| 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/12562/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4659fb3533f8b5435d9957f77bff68cb93ad8bede288f7ea66f2c523f1253a6c/python/typeshed/issues/12562 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4659fb3533f8b5435d9957f77bff68cb93ad8bede288f7ea66f2c523f1253a6c/python/typeshed/issues/12562 |
| og:image:alt | Since NumPy 2.1 all subtypes of numpy.number implement __lt__ that returns a numpy.bool (which isn't a builtins.bool), matching the runtime behavior (numpy/numpy#26942). But as was noticed in numpy... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jorenham |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width