Title: mypy rejects subclassing Any typed **kwargs entries within a function · Issue #22309 · python/mypy · GitHub
Open Graph Title: mypy rejects subclassing Any typed **kwargs entries within a function · Issue #22309 · python/mypy
X Title: mypy rejects subclassing Any typed **kwargs entries within a function · Issue #22309 · python/mypy
Description: (No AI or LLMs were used in finding or writing up this issue.) This bug is analogous to #21998 but for **kwargs instead of *args . Summary In Python and passing other type checkers (e.g. pyright 1.1.414 commandline and the pyright playgr...
Open Graph Description: (No AI or LLMs were used in finding or writing up this issue.) This bug is analogous to #21998 but for **kwargs instead of *args . Summary In Python and passing other type checkers (e.g. pyright 1....
X Description: (No AI or LLMs were used in finding or writing up this issue.) This bug is analogous to #21998 but for **kwargs instead of *args . Summary In Python and passing other type checkers (e.g. pyright 1....
Opengraph URL: https://github.com/python/mypy/issues/22309
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"mypy rejects subclassing Any typed **kwargs entries within a function","articleBody":"**(No AI or LLMs were used in finding or writing up this issue.)**\n\nThis bug is analogous to https://github.com/python/mypy/issues/21998 but for `**kwargs` instead of `*args` .\n\n**Summary**\n\nIn Python and passing other type checkers (e.g. pyright 1.1.414 commandline and the pyright playground ) it is ok to subclass an entry passed within the **kwargs which is typed as Any, but mypy 2.4.0 and recent master seem to reject this, inconsistent with the apparent intention of https://github.com/python/mypy/issues/5865 and https://github.com/python/mypy/pull/14135 .\n\n**To Reproduce**\n\nFor example, consider the following MyPy playground example modified off of https://github.com/python/mypy/blob/93b5e5101575551be20bda9f018498c62c2a30a6/test-data/unit/check-varargs.test#L763 to add an `Any` typed field to the `**kwargs` and try to subclass it: \n https://mypy-play.net/?gist=58c6c0424361c088e769d22bc04383f6&mypy=2.4.0&python=3.12\n```\nfrom typing import Unpack, TypedDict, Any\n\nclass Person(TypedDict):\n name: str\n age: int\n some_any_field: Any\n\ndef foo(arg: bool, **kwargs: Unpack[Person]) -> None:\n reveal_type(kwargs)\n reveal_type(kwargs['name'])\n reveal_type(kwargs['some_any_field'])\n # mypy says cannot subclass an explicit `Any` type here, inconsistent with https://github.com/python/mypy/issues/5865 and https://github.com/python/mypy/pull/14135\n # pyright allows it (it is a valid thing to do), see https://pyright-play.net/?code=GYJw9gtgBALgngBwJYDsDmUkQWEMoCqKCAhgMYDWANFACqICmAJgCJJkw0CCKcAUHzIAbEgGdRUAAoMQosCgAU9BMzYcAlAC4%2BUXVBQkIDTVFEwQOvSTTHMKGJd1yjAfRK8XwJAyFMTPfj4mBmAoYDAwBRIQNBMAIwihGgAqZIoAd2i0URMiUkoAbWlZeQBddSgAWgA%2BKAA5eWNHKBAGADcGEiEXeBUFDKzRdWbWjq6exn7MmNECgHIDIznykfbO7t6GKcH55wY3Dy8fJmXhvShhMQkAZQBXOO2Z3ch99zhPb19Tk1JxKABiKBtLpIJiwMCme6XP4MAAeCCE7CQ%2BACNAgiDgphIcAkKDADj4o3WEz64TA6iAA\n class Sub(kwargs['some_any_field']): pass\n\nreveal_type(foo)\n```\n\n\u003cimg width=\"1920\" height=\"1017\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/22a8aba2-a5a8-479c-a99e-54a7191a2cab\" />\n\n**Note that the same is recognized as valid in Pyright, e.g.** https://pyright-play.net/?code=GYJw9gtgBALgngBwJYDsDmUkQWEMoCqKCAhgMYDWANFACqICmAJgCJJkw0CCKcAUHzIAbEgGdRUAAoMQosCgAU9BMzYcAlAC4%2BUXVBQkIDTVFEwQOvSTTHMKGJd1yjAfRK8XwJAyFMTPfj4mBmAoYDAwBRIQNBMAIwihGgAqZIoAd2i0URMiUkoAbWlZeQBddSgAWgA%2BKAA5eWNHKBAGADcGEiEXeBUFDKzRdWbWjq6exn7MmNECgHIDIznykfbO7t6GKcH55wY3Dy8fJmXhvShhMQkAZQBXOO2Z3ch99zhPb19Tk1JxKABiKBtLpIJiwMCme6XP4MAAeCCE7CQ%2BACNAgiDgphIcAkKDADj4o3WEz64TA6iAA \n\n\u003cimg width=\"1920\" height=\"1017\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/a980a992-2813-4e1b-b625-ddbc325348ba\" />\n\n**Expected Behavior**\n\nMyPy, like Pyright (see link above), should recognize it is valid for explicitly `Any` typed kwargs entries to be subclassed, like MyPy already recognizes for explicitly `Any` typed parameters that are not `*args`, `**kwargs` or accessed by index.\n\n**Actual Behavior**\n\nMyPy treats explicit `Any` typed function arguments as valid bases if they are not in `**kwargs` (or `*args`) or accessed by index, but treats them as invalid inheritance bases if they are from `**kwargs` (or `*args`) .\n\n**Your Environment**\n\n- Mypy version used: 2.4.0 and recent master\n- Mypy command-line flags: see sandbox/playground link ( https://mypy-play.net/?gist=58c6c0424361c088e769d22bc04383f6&mypy=2.4.0&python=3.12 )\n- Mypy configuration options from `mypy.ini` (and other config files): https://mypy-play.net/?gist=58c6c0424361c088e769d22bc04383f6&mypy=2.4.0&python=3.12\n- Python version used: 3.12\n","author":{"url":"https://github.com/willy-b","@type":"Person","name":"willy-b"},"datePublished":"2026-10-27T21:58:48Z","url":"https://github.com/python/mypy/issues/22309"}
| 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:901adf5b-e507-bd97-d1a3-5212a8e50ed5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8A9C:3F7946:1EF7726:2A1255B:6B00197C |
| html-safe-nonce | 099e6a479cfdb3a72f1dd19f90899075509223d23668f86731050565efbd172c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QTlDOjNGNzk0NjoxRUY3NzI2OjJBMTI1NUI6NkIwMDE5N0MiLCJ2aXNpdG9yX2lkIjoiOTE2MTgyODM2MTM0Mzg2NzI2MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4a492494afc00445d5c7c379a6f9c616061d06a816fda64ec70325ab488caac8 |
| hovercard-subject-tag | issue:6068450234 |
| 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/22309/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8452464b41804bdbc2861f8970a5c8e67a747085aecd7d7687086d273ea8d246/python/mypy/issues/22309 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8452464b41804bdbc2861f8970a5c8e67a747085aecd7d7687086d273ea8d246/python/mypy/issues/22309 |
| og:image:alt | (No AI or LLMs were used in finding or writing up this issue.) This bug is analogous to #21998 but for **kwargs instead of *args . Summary In Python and passing other type checkers (e.g. pyright 1.... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | willy-b |
| 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