Title: TypedDict: Argument 1 to "f" has incompatible type "test.C"; expected "C" · Issue #5593 · python/mypy · GitHub
Open Graph Title: TypedDict: Argument 1 to "f" has incompatible type "test.C"; expected "C" · Issue #5593 · python/mypy
X Title: TypedDict: Argument 1 to "f" has incompatible type "test.C"; expected "C" · Issue #5593 · python/mypy
Description: The following code fails to typecheck: from typing import Any, Type, TypeVar from mypy_extensions import TypedDict _T = TypeVar('_T') class C(TypedDict): x: str class D: x: str def gen_row() -> Any: return {'x': 1} def foo(cls: Type[_T])...
Open Graph Description: The following code fails to typecheck: from typing import Any, Type, TypeVar from mypy_extensions import TypedDict _T = TypeVar('_T') class C(TypedDict): x: str class D: x: str def gen_row() -> Any...
X Description: The following code fails to typecheck: from typing import Any, Type, TypeVar from mypy_extensions import TypedDict _T = TypeVar('_T') class C(TypedDict): x: str class D: x: str def gen_row(...
Opengraph URL: https://github.com/python/mypy/issues/5593
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TypedDict: Argument 1 to \"f\" has incompatible type \"test.C\"; expected \"C\"","articleBody":"The following code fails to typecheck:\r\n\r\n```python\r\nfrom typing import Any, Type, TypeVar\r\nfrom mypy_extensions import TypedDict\r\n\r\n_T = TypeVar('_T')\r\n\r\nclass C(TypedDict):\r\n x: str\r\n\r\nclass D:\r\n x: str\r\n\r\ndef gen_row() -> Any:\r\n return {'x': 1}\r\n\r\ndef foo(cls: Type[_T]) -> _T:\r\n return gen_row()\r\n\r\ndef print_c(c: C):\r\n print(c)\r\n\r\ndef print_d(d: D):\r\n print(d)\r\n\r\nprint_c(foo(C))\r\nprint_d(foo(D))\r\nreveal_type(foo(C))\r\nreveal_type(foo(D))\r\n```\r\nproducing the following error:\r\n```\r\n$ mypy test.py\r\ntest.py:24: error: Argument 1 to \"print_c\" has incompatible type \"test.C\"; expected \"C\"\r\ntest.py:26: error: Revealed type is 'test.C*'\r\ntest.py:27: error: Revealed type is 'test.D*'\r\n```\r\n\r\nI think this is a bug related to `TypedDict`, as using any other class (like `D` in the sample code) works just fine.\r\n\r\nNote also that one cannot tighten `T` with a `bound=TypedDict`, as that produces the error:\r\n`Invalid type \"mypy_extensions.TypedDict\"`.\r\n\r\n* What are the versions of mypy and Python you are using?\r\n```\r\n$ mypy --version\r\nmypy 0.620\r\n$ python --version\r\nPython 3.6.5\r\n```\r\n\r\n* What are the mypy flags you are using? (For example --strict-optional)\r\n`mypy.ini` is:\r\n```ini\r\n[mypy]\r\nignore_missing_imports = True\r\nstrict_optional = True\r\nwarn_unused_ignores = True\r\nwarn_redundant_casts = True\r\nwarn_unused_configs = True\r\ncheck_untyped_defs = True\r\n```","author":{"url":"https://github.com/sk-","@type":"Person","name":"sk-"},"datePublished":"2018-09-10T15:24:02Z","url":"https://github.com/python/mypy/issues/5593"}
| 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:6291cb8f-b4f1-c327-a4f4-3aa8c29ef0a9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A8F0:30501:4854D4:61F413:6B002F13 |
| html-safe-nonce | 766b12d5dccd4ec2499a646f608103f8d029ef1df2cf3c5fc6ddfc0cb083bf02 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOEYwOjMwNTAxOjQ4NTRENDo2MUY0MTM6NkIwMDJGMTMiLCJ2aXNpdG9yX2lkIjoiMTQ1NzI3NzQyMzE2NTkxMDgwMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8784c25eba95bf00d15b3ea65096b2341751ef5b824ab292b459a3de5d3b078a |
| hovercard-subject-tag | issue:358673747 |
| 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/5593/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f0d70af84404c21368488e85f9e748b510fbace6210a3dd743d3f73e42a3aa08/python/mypy/issues/5593 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f0d70af84404c21368488e85f9e748b510fbace6210a3dd743d3f73e42a3aa08/python/mypy/issues/5593 |
| og:image:alt | The following code fails to typecheck: from typing import Any, Type, TypeVar from mypy_extensions import TypedDict _T = TypeVar('_T') class C(TypedDict): x: str class D: x: str def gen_row() -> Any... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sk- |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width