Title: Cannot turn existing dictionary into TypedDict · Issue #8890 · python/mypy · GitHub
Open Graph Title: Cannot turn existing dictionary into TypedDict · Issue #8890 · python/mypy
X Title: Cannot turn existing dictionary into TypedDict · Issue #8890 · python/mypy
Description: I expected any of these forms to be allowed by MyPy, but they aren't: # typed_dict_test.py from typing import TypedDict class D(TypedDict): a: str b: int d_untyped = {"a": "foo", "b": 1} d0 = D({"a": "foo", "b": 1}) # The only one that w...
Open Graph Description: I expected any of these forms to be allowed by MyPy, but they aren't: # typed_dict_test.py from typing import TypedDict class D(TypedDict): a: str b: int d_untyped = {"a": "foo", "b": 1} d0 = D({"a...
X Description: I expected any of these forms to be allowed by MyPy, but they aren't: # typed_dict_test.py from typing import TypedDict class D(TypedDict): a: str b: int d_untyped = {"a": "foo&q...
Opengraph URL: https://github.com/python/mypy/issues/8890
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Cannot turn existing dictionary into TypedDict","articleBody":"I expected any of these forms to be allowed by MyPy, but they aren't:\r\n\r\n```python\r\n# typed_dict_test.py\r\nfrom typing import TypedDict\r\n\r\nclass D(TypedDict):\r\n a: str\r\n b: int\r\n\r\n\r\nd_untyped = {\"a\": \"foo\", \"b\": 1}\r\n\r\nd0 = D({\"a\": \"foo\", \"b\": 1}) # The only one that works\r\nprint(d0)\r\n\r\nd1 = D(d_untyped)\r\nprint(d1)\r\n\r\nd2 = D(**d_untyped)\r\nprint(d2)\r\n\r\nd3 = D(dict(d_untyped))\r\nprint(d3)\r\n\r\nd4 = D(dict(**d_untyped))\r\nprint(d4)\r\n```\r\n\r\n```\r\n$ python typed_dict_test.py\r\n{'a': 'foo', 'b': 1}\r\n{'a': 'foo', 'b': 1}\r\n{'a': 'foo', 'b': 1}\r\n{'a': 'foo', 'b': 1}\r\n{'a': 'foo', 'b': 1}\r\n$ python -V\r\nPython 3.8.3\r\n$ mypy typed_dict_test.py \r\ntyped_dict_test.py:13: error: Expected keyword arguments, {...}, or dict(...) in TypedDict constructor [misc]\r\n d1 = D(d_untyped)\r\n ^\r\ntyped_dict_test.py:16: error: Expected keyword arguments, {...}, or dict(...) in TypedDict constructor [misc]\r\n d2 = D(**d_untyped)\r\n ^\r\ntyped_dict_test.py:19: error: Expected keyword arguments, {...}, or dict(...) in TypedDict constructor [misc]\r\n d3 = D(dict(d_untyped))\r\n ^\r\ntyped_dict_test.py:22: error: Expected keyword arguments, {...}, or dict(...) in TypedDict constructor [misc]\r\n d4 = D(dict(**d_untyped))\r\n ^\r\nFound 4 errors in 1 file (checked 1 source file)\r\n$ cat mypy.ini \r\n[mypy]\r\nwarn_redundant_casts = True\r\nwarn_unused_configs = True\r\npretty = True\r\nshow_error_codes = True\r\n\r\ndisallow_any_generics = True\r\ndisallow_subclassing_any = True\r\ndisallow_untyped_calls = True\r\ndisallow_incomplete_defs = True\r\ncheck_untyped_defs = True\r\ndisallow_untyped_decorators = True\r\nno_implicit_optional = True\r\nwarn_unused_ignores = True\r\nwarn_return_any = True\r\nno_implicit_reexport = True\r\n```\r\n\r\nI checked that `cast(D, ...)` works, but I wonder if this is the right way to proceed, or a workaround.","author":{"url":"https://github.com/astrojuanlu","@type":"Person","name":"astrojuanlu"},"datePublished":"2020-05-26T07:15:45Z","url":"https://github.com/python/mypy/issues/8890"}
| 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:e7073a6f-f014-df59-0044-c383a85b1f55 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E064:2B3CBD:125928D:180DCEA:6B000CE0 |
| html-safe-nonce | 40e27fcf158a4486cf018926983f4054938bbe365037ac7bd745c331b8209d5c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMDY0OjJCM0NCRDoxMjU5MjhEOjE4MERDRUE6NkIwMDBDRTAiLCJ2aXNpdG9yX2lkIjoiODgzMDM3Mzg1MDkzNzAzNjAwMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 646a6dca1d1a38487b231b2f4560d015c5ddb45ca5820e35014d92d010c2af29 |
| hovercard-subject-tag | issue:624653649 |
| 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/8890/issue_layout |
| twitter:image | https://opengraph.githubassets.com/64f79fa0c07a5038e6a101361e246c479685415d59cea6980233c5beece9c8f4/python/mypy/issues/8890 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/64f79fa0c07a5038e6a101361e246c479685415d59cea6980233c5beece9c8f4/python/mypy/issues/8890 |
| og:image:alt | I expected any of these forms to be allowed by MyPy, but they aren't: # typed_dict_test.py from typing import TypedDict class D(TypedDict): a: str b: int d_untyped = {"a": "foo", "b": 1} d0 = D({"a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | astrojuanlu |
| hostname | github.com |
| expected-hostname | github.com |
| None | cf7ee0062053ad9eb05b6e5de57bd96c2055708bcbada4144946b5ec129cf1d7 |
| 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 | 9cab7de176a56362d2aabcbb4d1e07e846eba8a0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width