Title: `NamedTuple` can't inherit from another class · Issue #116241 · python/cpython · GitHub
Open Graph Title: `NamedTuple` can't inherit from another class · Issue #116241 · python/cpython
X Title: `NamedTuple` can't inherit from another class · Issue #116241 · python/cpython
Description: Feature or enhancement Proposal: Currently this code is failing: class A: pass class B(A, typing.NamedTuple): x: int Raising: TypeError: can only inherit from a NamedTuple type and Generic But this code is not: class A: pass class _B(typ...
Open Graph Description: Feature or enhancement Proposal: Currently this code is failing: class A: pass class B(A, typing.NamedTuple): x: int Raising: TypeError: can only inherit from a NamedTuple type and Generic But this...
X Description: Feature or enhancement Proposal: Currently this code is failing: class A: pass class B(A, typing.NamedTuple): x: int Raising: TypeError: can only inherit from a NamedTuple type and Generic But this...
Opengraph URL: https://github.com/python/cpython/issues/116241
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`NamedTuple` can't inherit from another class","articleBody":"# Feature or enhancement\n\n### Proposal:\n\nCurrently this code is failing:\n\n```python\nclass A:\n pass\n\nclass B(A, typing.NamedTuple):\n x: int\n```\n\nRaising:\n\n```\nTypeError: can only inherit from a NamedTuple type and Generic\n```\n\nBut this code is not:\n\n```python\nclass A:\n pass\n\nclass _B(typing.NamedTuple):\n x: int\n\nclass B(A, _B):\n pass\n\nB(x=1)\n```\n\nI believe those 2 snippets are mostly equivalent (the final `B` class behave the same), so it's confusing and force boilerplate that `class B(A, typing.NamedTuple):` fail.\n\n\n### Has this already been discussed elsewhere?\n\nThis is a minor feature, which does not need previous discussion elsewhere\n\n### Links to previous discussion of this feature:\n\n_No response_\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-31781\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/Conchylicultor","@type":"Person","name":"Conchylicultor"},"datePublished":"2024-03-02T12:30:13.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":24},"url":"https://github.com/116241/cpython/issues/116241"}
| 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:777c3455-820e-703a-9dca-9a4daa1c70e6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CD86:C9338:574E52:71B96B:696B0D83 |
| html-safe-nonce | 1829564b4cbd1d1deb2e228007deb5105e02d197d295d4ec0d2194becefccc80 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRDg2OkM5MzM4OjU3NEU1Mjo3MUI5NkI6Njk2QjBEODMiLCJ2aXNpdG9yX2lkIjoiNjk5NTYxMzQ3MTg4MTIzNTg0MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | cf131c451e403577bb600e1c78744fb71752bed81c8998331d768c9e4ed25542 |
| hovercard-subject-tag | issue:2164789132 |
| 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/116241/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6416120532e64183458b5be0a9f42714cb0cc26af701e89ed81fbd5fbc5ece24/python/cpython/issues/116241 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6416120532e64183458b5be0a9f42714cb0cc26af701e89ed81fbd5fbc5ece24/python/cpython/issues/116241 |
| og:image:alt | Feature or enhancement Proposal: Currently this code is failing: class A: pass class B(A, typing.NamedTuple): x: int Raising: TypeError: can only inherit from a NamedTuple type and Generic But this... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Conchylicultor |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| 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 | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width