Title: Overload resolution collapses to Any when Any is nested inside a generic argument, not just top-level · Issue #21768 · python/mypy · GitHub
Open Graph Title: Overload resolution collapses to Any when Any is nested inside a generic argument, not just top-level · Issue #21768 · python/mypy
X Title: Overload resolution collapses to Any when Any is nested inside a generic argument, not just top-level · Issue #21768 · python/mypy
Description: Bug Report The docs state the return type becomes Any only when "an argument [is] of type Any". But when the Any is nested inside a generic type argument (Sequence[Any] vs Sequence[int]), mypy also collapses the result to Any, even thoug...
Open Graph Description: Bug Report The docs state the return type becomes Any only when "an argument [is] of type Any". But when the Any is nested inside a generic type argument (Sequence[Any] vs Sequence[int]), mypy also...
X Description: Bug Report The docs state the return type becomes Any only when "an argument [is] of type Any". But when the Any is nested inside a generic type argument (Sequence[Any] vs Sequence[int]),...
Opengraph URL: https://github.com/python/mypy/issues/21768
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Overload resolution collapses to Any when Any is nested inside a generic argument, not just top-level","articleBody":"**Bug Report**\n\nThe docs state the return type becomes Any only when \"an argument [is] of type Any\". But when the Any is nested inside a generic type argument (Sequence[Any] vs Sequence[int]), mypy also collapses the result to Any, even though the first overload matches unambiguously. Is this intended? If so, the \"Type checking calls to overloads\" section should probably document the nested case.\n\n**To Reproduce**\n\n```\nfrom collections.abc import Sequence\nfrom typing import Any, overload, reveal_type\n\n\n@overload\ndef f(s: Sequence[int]) -> str: ...\n@overload\ndef f(s: object) -> int: ...\ndef f(s: object) -> int | str:\n return \"2\"\n\n\nconcrete: Sequence[int] = [1]\nnested_any: Sequence[Any] = [1]\n\nreveal_type(f(concrete)) # Revealed type is \"str\" (expected)\nreveal_type(f(nested_any)) # Revealed type is \"Any\" (surprising)\n```\n\n**Expected Behavior**\n\nreveal_type on Sequence[Any] should show \"str\"\n\n**Actual Behavior**\n\nreveal_type on Sequence[Any] shows \"Any\"\n\n**Your Environment**\n\n\u003c!-- Include as many relevant details about the environment you experienced the bug in -->\n\n- Mypy version used: mypy 2.3.0\n- Mypy command-line flags: none\n- Mypy configuration options from `mypy.ini` (and other config files): none\n- Python version used: Python 3.14.6\n\n","author":{"url":"https://github.com/dpinol","@type":"Person","name":"dpinol"},"datePublished":"2026-07-23T08:59:42Z","url":"https://github.com/python/mypy/issues/21768"}
| 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:2b8fd71c-995f-b682-f073-c9836ed8f515 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ABB2:3EE8F1:15B8D5E:1CA4CE5:6B00156F |
| html-safe-nonce | deb7fa9c1a233f2723c5b2b493b720dc78c6adb07f0cc26c4bacf40725aaac64 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQkIyOjNFRThGMToxNUI4RDVFOjFDQTRDRTU6NkIwMDE1NkYiLCJ2aXNpdG9yX2lkIjoiMTg3OTYwMzcwOTE2MDE5OTUzNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9e12493feb106d735936c35b380f3fd790f264c75a4bcde09c30b88d2127da2c |
| hovercard-subject-tag | issue:4957193129 |
| 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/21768/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dd23aee70176482fb754bd926880638955c859e7c6f88c24eaa97e38a6c735b1/python/mypy/issues/21768 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dd23aee70176482fb754bd926880638955c859e7c6f88c24eaa97e38a6c735b1/python/mypy/issues/21768 |
| og:image:alt | Bug Report The docs state the return type becomes Any only when "an argument [is] of type Any". But when the Any is nested inside a generic type argument (Sequence[Any] vs Sequence[int]), mypy also... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dpinol |
| 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