Title: Argument "key" to "sorted" has incompatible type "Callable…" · Issue #19259 · python/mypy · GitHub
Open Graph Title: Argument "key" to "sorted" has incompatible type "Callable…" · Issue #19259 · python/mypy
X Title: Argument "key" to "sorted" has incompatible type "Callable…" · Issue #19259 · python/mypy
Description: Bug Report I believe that I've found a bug in mypy, the following MRE should as far as I can tell not result in any typing errors at all, but it reports an error (and I've found two simple workarounds for which no error is reported, stre...
Open Graph Description: Bug Report I believe that I've found a bug in mypy, the following MRE should as far as I can tell not result in any typing errors at all, but it reports an error (and I've found two simple workarou...
X Description: Bug Report I believe that I've found a bug in mypy, the following MRE should as far as I can tell not result in any typing errors at all, but it reports an error (and I've found two simple ...
Opengraph URL: https://github.com/python/mypy/issues/19259
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Argument \"key\" to \"sorted\" has incompatible type \"Callable…\"","articleBody":"**Bug Report**\n\nI believe that I've found a bug in mypy, the following MRE should as far as I can tell not result in any typing errors at all, but it reports an error (and I've found two simple workarounds for which no error is reported, strengthening my belief that this is a bug and not intended behaviour).\n\n**To Reproduce**\n\n```python\n#!/usr/bin/python3\n\nfrom collections.abc import Iterable\nfrom typing import cast\n\n\ndef unproblematic(iter: Iterable[int]) -> None:\n print(iter)\n\n\ndef problematic(iter: Iterable[int | str]) -> None:\n print(iter)\n\n\ndef key(item: int) -> int:\n return -item\n\n\ndef main() -> None:\n items: list[int] = [3, 4, 1, 2]\n\n unproblematic(sorted(items, key=key)) # Works.\n problematic(sorted(items, key=key)) # Fails mypy arg-type.\n\n workaround = sorted(items, key=key)\n problematic(workaround) # Works.\n\n problematic(cast(Iterable[int], sorted(items, key=key))) # Works.\n\n\nif __name__ == '__main__':\n main()\n```\n\n**Actual Behavior**\n\n```sh\n$ mypy mre.py\nmre.py:23: error: Argument \"key\" to \"sorted\" has incompatible type \"Callable[[int], int]\"; expected \"Callable[[int | str], SupportsDunderLT[Any] | SupportsDunderGT[Any]]\" [arg-type]\n```\n\n**Your Environment**\n\n```sh\n$ mypy --version \nmypy 1.16.0 (compiled: yes)\n$ python3 --version\nPython 3.13.3\n```\n\n(If anyone can't trivially reproduce this, I'd be happy to provide more details about my environment.)","author":{"url":"https://github.com/roubert","@type":"Person","name":"roubert"},"datePublished":"2025-06-09T08:41:50Z","url":"https://github.com/python/mypy/issues/19259"}
| 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:d1a50223-8f79-7ea1-1746-85e5f5eaa49a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E6D0:11BB24:2045EA5:2BBA4C2:6B001978 |
| html-safe-nonce | 6ba91621977e8c898cf4474a9280de9c34ff4bd17475ca91e10ff6b514058dd6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNkQwOjExQkIyNDoyMDQ1RUE1OjJCQkE0QzI6NkIwMDE5NzgiLCJ2aXNpdG9yX2lkIjoiNTAzODk4OTk1MzI0NjIzMjI0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | f4d4d2a51a3ec3c08e58ba3a3e36e957a68b1c67a3b86e4acf97ec09186aa5d2 |
| hovercard-subject-tag | issue:3129608601 |
| 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/mypy/19259/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3ca1419c603f9e7438d8e60ba3c1a2b92031c30f8d65ac7d6b577b3cbf47e698/python/mypy/issues/19259 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3ca1419c603f9e7438d8e60ba3c1a2b92031c30f8d65ac7d6b577b3cbf47e698/python/mypy/issues/19259 |
| og:image:alt | Bug Report I believe that I've found a bug in mypy, the following MRE should as far as I can tell not result in any typing errors at all, but it reports an error (and I've found two simple workarou... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | roubert |
| hostname | github.com |
| expected-hostname | github.com |
| None | a2dd2291b1b13cc9c06f27ec92fa3dbaf34116fc24c9347b8539db61884c59f4 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| 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 | 70121d4e855ee0bb7b75cf15d061d91f8863c0f8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width