Title: Function with generic class and generic value arguments are not inferred when generic is a TypedDict · Issue #19201 · python/mypy · GitHub
Open Graph Title: Function with generic class and generic value arguments are not inferred when generic is a TypedDict · Issue #19201 · python/mypy
X Title: Function with generic class and generic value arguments are not inferred when generic is a TypedDict · Issue #19201 · python/mypy
Description: Bug Report When defining a function expecting a generic class and a generic value — tied to the same TypeVar —, mypy is not able to infer the type of the argument if the generic type is a TypedDict. It works well for scalar types, if the...
Open Graph Description: Bug Report When defining a function expecting a generic class and a generic value — tied to the same TypeVar —, mypy is not able to infer the type of the argument if the generic type is a TypedDict...
X Description: Bug Report When defining a function expecting a generic class and a generic value — tied to the same TypeVar —, mypy is not able to infer the type of the argument if the generic type is a TypedDict...
Opengraph URL: https://github.com/python/mypy/issues/19201
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Function with generic class and generic value arguments are not inferred when generic is a TypedDict","articleBody":"\u003c!--\nIf you're not sure whether what you're experiencing is a mypy bug, please see the \"Question and Help\" form instead.\nPlease consider:\n\n- checking our common issues page: https://mypy.readthedocs.io/en/stable/common_issues.html\n- searching our issue tracker: https://github.com/python/mypy/issues to see if it's already been reported\n- asking on gitter chat: https://gitter.im/python/typing\n-->\n\n**Bug Report**\n\n\u003c!--\nIf you're reporting a problem with a specific library function, the typeshed tracker is better suited for this report: https://github.com/python/typeshed/issues\n\nIf the project you encountered the issue in is open source, please provide a link to the project.\n-->\n\nWhen defining a function expecting a generic class and a generic value — tied to the same `TypeVar` —, mypy is not able to infer the type of the argument if the generic type is a `TypedDict`.\n\nIt works well for scalar types, if the variable is explicitly defined as the typed dict type, or even more surprising, if the first generic argument is binded via a `functools.partial`.\n\n**To Reproduce**\n\nhttps://mypy-play.net/?mypy=latest&python=3.12&gist=a6d36519fbd58e5c9b77999eedd16132\n\n```python\nimport typing\nimport functools\n\nT = typing.TypeVar(\"T\")\n\n\nclass A(typing.Generic[T]): ...\n\n\ndef f(a: A[T], t: T) -> None: ...\n\n\nclass D(typing.TypedDict):\n x: int\n\n\na_typed_dict = A[D]()\nf(a_typed_dict, {\"x\": 1}) # error: Cannot infer type argument 1 of \"f\" [misc]\n```\n\n**Expected Behavior**\n\nThe `t` argument is correctly validated as a `D` typed dict.\n\n**Actual Behavior**\n\nThe following error message is returned:\n\n```\nerror: Cannot infer type argument 1 of \"f\" [misc]\n```\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: 1.15\n- Python version used: 3.12\n\n\u003c!-- You can freely edit this text, please remove all the lines you believe are unnecessary. -->\n","author":{"url":"https://github.com/frankie567","@type":"Person","name":"frankie567"},"datePublished":"2025-06-02T06:39:55Z","url":"https://github.com/python/mypy/issues/19201"}
| 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:490efef8-5113-2d4a-600d-7644016e7d0c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 81AC:59847:A412B:DD0B0:6B001C1F |
| html-safe-nonce | 38af68b233e1e7d32cd7bd4f002502d5a56bd3a34a77e633d2f5f2f4903e170f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MUFDOjU5ODQ3OkE0MTJCOkREMEIwOjZCMDAxQzFGIiwidmlzaXRvcl9pZCI6IjE2NzA5MDY1OTY3OTc5Nzk2NzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a0e254ed1c36e87282b6f2212694d9dffb78bcece3da2b815b23385133f55ece |
| hovercard-subject-tag | issue:3108818734 |
| 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/19201/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9bf2a5d1bcc782ace006e24be204ff15c597eac50ae859ac4a1b89987f5308e4/python/mypy/issues/19201 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9bf2a5d1bcc782ace006e24be204ff15c597eac50ae859ac4a1b89987f5308e4/python/mypy/issues/19201 |
| og:image:alt | Bug Report When defining a function expecting a generic class and a generic value — tied to the same TypeVar —, mypy is not able to infer the type of the argument if the generic type is a TypedDict... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | frankie567 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width