Title: Possible false positive calling dict.update() method with TypedDict hierarchy · Issue #9335 · python/mypy · GitHub
Open Graph Title: Possible false positive calling dict.update() method with TypedDict hierarchy · Issue #9335 · python/mypy
X Title: Possible false positive calling dict.update() method with TypedDict hierarchy · Issue #9335 · python/mypy
Description: Python version: 3.8.2 mypy version: 0.782 mypy flags: --strict (same result without this flag) I've encountered what looks like a false positive when calling .update() on TypedDicts that have some required and some optional fields. I hav...
Open Graph Description: Python version: 3.8.2 mypy version: 0.782 mypy flags: --strict (same result without this flag) I've encountered what looks like a false positive when calling .update() on TypedDicts that have some ...
X Description: Python version: 3.8.2 mypy version: 0.782 mypy flags: --strict (same result without this flag) I've encountered what looks like a false positive when calling .update() on TypedDicts that have s...
Opengraph URL: https://github.com/python/mypy/issues/9335
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Possible false positive calling dict.update() method with TypedDict hierarchy","articleBody":"Python version: 3.8.2\r\nmypy version: 0.782\r\nmypy flags: --strict (same result without this flag)\r\n\r\nI've encountered what looks like a false positive when calling `.update()` on TypedDicts that have some required and some optional fields. I have a hierarchy of TypedDicts with some required fields in the base class and some optional fields in the derived class. Here is a minimal snippet that reproduces the error:\r\n```python3\r\nfrom typing import TypedDict\r\n\r\n\r\nclass Base(TypedDict):\r\n id: int\r\n\r\n\r\nclass Derived(Base, total=False):\r\n description: str\r\n\r\n\r\nupdate_me: Derived = {\r\n 'id': 1,\r\n 'description': 'norsetanrst'\r\n}\r\n\r\nnew_data: Derived = {\r\n 'id': 2\r\n}\r\n# \"incompatible type\" error from mypy\r\nupdate_me.update(new_data)\r\n```\r\n\r\nI expected this to type check with no errors. However, mypy emits the following about the last line:\r\n```\r\n$ mypy --strict\r\ndemo.py:21: error: Argument 1 to \"update\" of \"TypedDict\" has incompatible type \"Derived\"; expected \"TypedDict({'content'?: Dict[str, int], 'description'?: str})\"\r\nFound 1 error in 1 file (checked 1 source file)\r\n```\r\n\r\nIt seems like mypy is expecting a TypedDict with the same fields (but all optional) as Derived. If I change the last line to `update_me.update(update_me)`, the same error occurs. If I add `total=False` to `Base`'s signature, the error goes away, but then I no longer have any required fields.\r\n\r\nAlso interesting to note: `reveal_type(update_me.update)` prints the signature I would expect:\r\n```\r\nnote: Revealed type is 'def (TypedDict('wee.Derived', {'id': builtins.int, 'description'?: builtins.str}))'\r\n```\r\nAnd if I inline the argument, i.e. `update_me.update({'id': 2})`, the error goes away. However, my use case is\r\nsuch that doing so is not a viable solution.\r\n\r\nThank you! Please let me know if there's anything I've missed.","author":{"url":"https://github.com/james-perretta","@type":"Person","name":"james-perretta"},"datePublished":"2020-08-21T20:44:15Z","url":"https://github.com/python/mypy/issues/9335"}
| 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:073d33fc-3152-0f9f-b115-66596c46c9c4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D4F6:3CF916:36ED87:4CE6E4:6B005E37 |
| html-safe-nonce | 8ff530574b2feaf4dcaf9825e1816e40cdf4dd3a8b0981fb5eff870b937d3935 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENEY2OjNDRjkxNjozNkVEODc6NENFNkU0OjZCMDA1RTM3IiwidmlzaXRvcl9pZCI6IjY1NDUwMTc1MjY0ODc2Mzc1NTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 778c276f979ea102d65f1f39f7caed04ba7dd36fd9506a382b922ae1dc152010 |
| hovercard-subject-tag | issue:683818403 |
| 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/9335/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b5492423768ec3df96e4ab835d47ff03db058b3fcb0daf3a89daf0e9b258a837/python/mypy/issues/9335 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b5492423768ec3df96e4ab835d47ff03db058b3fcb0daf3a89daf0e9b258a837/python/mypy/issues/9335 |
| og:image:alt | Python version: 3.8.2 mypy version: 0.782 mypy flags: --strict (same result without this flag) I've encountered what looks like a false positive when calling .update() on TypedDicts that have some ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | james-perretta |
| hostname | github.com |
| expected-hostname | github.com |
| None | 29be975efff6507a5d135de9c7d634cf7ff8f0c55222a64386ab3202209aaf73 |
| 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 | eacd927ba6112e3b01ba99c762bd699a4a4f5df7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width