Title: Deprecate unusual ways of creating `typing.NamedTuple` classes · Issue #105566 · python/cpython · GitHub
Open Graph Title: Deprecate unusual ways of creating `typing.NamedTuple` classes · Issue #105566 · python/cpython
X Title: Deprecate unusual ways of creating `typing.NamedTuple` classes · Issue #105566 · python/cpython
Description: Feature or enhancement I propose that we deprecate in Python 3.13 the following unusual ways of constructing a typing.NamedTuple: from typing import NamedTuple Foo = NamedTuple("Foo", x=int, y=int) # NamedTuple with "x" and "y" fields Ba...
Open Graph Description: Feature or enhancement I propose that we deprecate in Python 3.13 the following unusual ways of constructing a typing.NamedTuple: from typing import NamedTuple Foo = NamedTuple("Foo", x=int, y=int)...
X Description: Feature or enhancement I propose that we deprecate in Python 3.13 the following unusual ways of constructing a typing.NamedTuple: from typing import NamedTuple Foo = NamedTuple("Foo", x=i...
Opengraph URL: https://github.com/python/cpython/issues/105566
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Deprecate unusual ways of creating `typing.NamedTuple` classes","articleBody":"# Feature or enhancement\r\n\r\nI propose that we deprecate in Python 3.13 the following unusual ways of constructing a `typing.NamedTuple`:\r\n\r\n```py\r\nfrom typing import NamedTuple\r\n\r\nFoo = NamedTuple(\"Foo\", x=int, y=int) # NamedTuple with \"x\" and \"y\" fields\r\nBar = NamedTuple(\"Bar\") # empty NamedTuple\r\nBaz = NamedTuple(\"Baz\", None) # empty NamedTuple\r\nEggs = NamedTuple(\"Eggs\", fields=None) # empty NamedTuple\r\n```\r\n\r\n# Pitch\r\n\r\n`typing.NamedTuple` has been around for quite a while now, but none of the above methods of constructing `NamedTuple`s are supported by type checkers. If they're still unsupported by type checkers after all this time, they're unlikely to ever be supported by type checkers.\r\n\r\nDeprecating, and eventually removing, these ways of constructing `NamedTuple`s will allow us to simplify the code at runtime. It will also be less confusing for users. Every way in which the runtime and type checkers differ in behaviour is a potential point of confusion for users; in general, we should work to keep these points of difference to a minimum.\r\n\r\nThese methods of constructing `NamedTuple`s are not commonly seen in the wild. They're also pretty redundant -- if you want to construct a `NamedTuple` in one line, in a single function call, you can do it like this, which is supported by type checkers:\r\n\r\n```py\r\nFoo = NamedTuple(\"Foo\", [(\"x\", int), (\"y\", int)])\r\n```\r\n\r\nIf you want to construct an empty `NamedTuple`, meanwhile, you can do it in one of the following two ways, which are both supported by type checkers:\r\n\r\n```py\r\nBar = NamedTuple(\"Bar\", [])\r\nclass Baz(NamedTuple): ...\r\n```\r\n\r\n# Previous discussion\r\n\r\nFor very similar reasons, we previously deprecated and removed the keyword-argument syntax for creating TypedDicts. This was deprecated in 3.11, and removed in 3.13:\r\n- #90224\r\n- #104786\r\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-105609\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/AlexWaygood","@type":"Person","name":"AlexWaygood"},"datePublished":"2023-06-09T15:01:57Z","url":"https://github.com/python/cpython/issues/105566"}
| 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:9c5c694e-9cbb-3d9d-a3a0-240698e839fc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A6D8:7F150:165F958:1D81447:6B001645 |
| html-safe-nonce | 8a17f53c88fb517aaf3aaf4f32396b1ead5ca88717eae221bfdcdc7619adc26d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNkQ4OjdGMTUwOjE2NUY5NTg6MUQ4MTQ0Nzo2QjAwMTY0NSIsInZpc2l0b3JfaWQiOiI2NjI3MzExNDgzNTg1ODI4NDIxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b02a42bc16657cdda346816f707b807b37e7e65282c848a2cd8a3f3c7c7864bc |
| hovercard-subject-tag | issue:1750064295 |
| 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/cpython/105566/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8c1c9e85291026feac828fc0251578b1f5f6f93383638276e923e9837cf024a1/python/cpython/issues/105566 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8c1c9e85291026feac828fc0251578b1f5f6f93383638276e923e9837cf024a1/python/cpython/issues/105566 |
| og:image:alt | Feature or enhancement I propose that we deprecate in Python 3.13 the following unusual ways of constructing a typing.NamedTuple: from typing import NamedTuple Foo = NamedTuple("Foo", x=int, y=int)... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | AlexWaygood |
| hostname | github.com |
| expected-hostname | github.com |
| None | a2dd2291b1b13cc9c06f27ec92fa3dbaf34116fc24c9347b8539db61884c59f4 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| 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