Title: TypedDict handles unicode names and keys inconsistently in Python 2 · Issue #6123 · python/mypy · GitHub
Open Graph Title: TypedDict handles unicode names and keys inconsistently in Python 2 · Issue #6123 · python/mypy
X Title: TypedDict handles unicode names and keys inconsistently in Python 2 · Issue #6123 · python/mypy
Description: I noticed an minor inconsistency in the way mypy handles the following program in Python 2: from __future__ import unicode_literals from mypy_extensions import TypedDict MyDict = TypedDict('MyDict', {'foo': int}) Mypy type-checks this pr...
Open Graph Description: I noticed an minor inconsistency in the way mypy handles the following program in Python 2: from __future__ import unicode_literals from mypy_extensions import TypedDict MyDict = TypedDict('MyDict'...
X Description: I noticed an minor inconsistency in the way mypy handles the following program in Python 2: from __future__ import unicode_literals from mypy_extensions import TypedDict MyDict = TypedDict('MyD...
Opengraph URL: https://github.com/python/mypy/issues/6123
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TypedDict handles unicode names and keys inconsistently in Python 2","articleBody":"I noticed an minor inconsistency in the way mypy handles the following program in Python 2:\r\n\r\n from __future__ import unicode_literals\r\n from mypy_extensions import TypedDict\r\n \r\n MyDict = TypedDict('MyDict', {'foo': int})\r\n\r\nMypy type-checks this problem without errors. However, if you actually try running this program at runtime, you get the following exception:\r\n\r\n```\r\nTraceback (most recent call last):\r\n File \"\u003cstdin>\", line 1, in \u003cmodule>\r\n File \"C:\\Python27\\lib\\site-packages\\mypy_extensions.py\", line 40, in _typeddict_new\r\n '__total__': total})\r\n File \"C:\\Python27\\lib\\site-packages\\mypy_extensions.py\", line 52, in __new__\r\n tp_dict = super(_TypedDictMeta, cls).__new__(cls, name, (dict,), ns)\r\nTypeError: type() argument 1 must be string, not unicode\r\n```\r\n\r\nYou have to do `MyDict = TypedDict(b'MyDict', {'foo': int})` to get this program to both typecheck and run.\r\n\r\nI'm not sure whether the correct thing to do is modify mypy to report an error or to relax the runtime implementation. \r\n\r\nOn one hand, `type(name, bases, dict)` legitimately won't accept unicode names in Python 2 so perhaps we should add a check to mypy. On the other, we don't get the same kind of runtime error when creating `NamedTuples`, so perhaps it's better to try and convert the unicode name to str inside `TypedDict` for consistency.\r\n","author":{"url":"https://github.com/Michael0x2a","@type":"Person","name":"Michael0x2a"},"datePublished":"2019-01-01T01:30:12Z","url":"https://github.com/python/mypy/issues/6123"}
| 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:e1a1682a-c98d-ca81-0e45-5ff3f09e636a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E89A:3FBC49:6450B:86768:6B001870 |
| html-safe-nonce | 6fd6e2eda12ed41779354dca8e4690a7891f586afb320fb14767bfe13ea52262 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFODlBOjNGQkM0OTo2NDUwQjo4Njc2ODo2QjAwMTg3MCIsInZpc2l0b3JfaWQiOiI0MjQ0NzMxNDAxNzk2MDY1MzkyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | bbdb5253e6ef1c751d9238685daee9dd15613ae68a1ab7e530ec0a86bb268788 |
| hovercard-subject-tag | issue:395047828 |
| 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/6123/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cb9fb7fcf1a2169d5c69977031ef68d11d405abd2b06a0fa0c5afe0c233e1f13/python/mypy/issues/6123 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cb9fb7fcf1a2169d5c69977031ef68d11d405abd2b06a0fa0c5afe0c233e1f13/python/mypy/issues/6123 |
| og:image:alt | I noticed an minor inconsistency in the way mypy handles the following program in Python 2: from __future__ import unicode_literals from mypy_extensions import TypedDict MyDict = TypedDict('MyDict'... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Michael0x2a |
| 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