Title: `NamedTuple`s cannot have nested classes · Issue #15775 · python/mypy · GitHub
Open Graph Title: `NamedTuple`s cannot have nested classes · Issue #15775 · python/mypy
X Title: `NamedTuple`s cannot have nested classes · Issue #15775 · python/mypy
Description: Python allows class definitions inside NamedTuple bodies: >>> from typing import NamedTuple >>> class A(NamedTuple): ... class B: ... ... >>> A.B
Open Graph Description: Python allows class definitions inside NamedTuple bodies: >>> from typing import NamedTuple >>> class A(NamedTuple): ... class B: ... ... >>> A.B X Description: Python allows class definitions inside NamedTuple bodies: >>> from typing import NamedTuple >>> class A(NamedTuple): ... class B: ... ... >>> A.B <class '__main__....
Opengraph URL: https://github.com/python/mypy/issues/15775
X: @github
Domain: github.com
Links:
Viewport: width=device-width
Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`NamedTuple`s cannot have nested classes","articleBody":"Python allows `class` definitions inside `NamedTuple` bodies:\r\n\r\n\r\n```python\r\n>>> from typing import NamedTuple\r\n>>> class A(NamedTuple):\r\n... class B: ...\r\n... \r\n>>> A.B\r\n\u003cclass '__main__.A.B'>\r\n>>> A().B\r\n\u003cclass '__main__.A.B'>\r\n```\r\n\r\nBut, `mypy` does not allow this:\r\n\r\n```python\r\nfrom typing import NamedTuple\r\n\r\nclass A(NamedTuple):\r\n class B: ... # E: Invalid statement in NamedTuple definition; expected \"field_name: field_type [= default]\"\r\n\r\nreveal_type(A.B) # E: \"type[A]\" has no attribute \"B\"\r\n# N: Revealed type is \"Any\"\r\n```\r\n\r\nI think that this is a bug that needs to be solved, because we don't have any reason not to allow this (my existing patch shows that semanal and typechecker are happy with allowing these classes).\r\n\r\nThis is the root cause of https://github.com/python/mypy/issues/15752\r\n","author":{"url":"https://github.com/sobolevn","@type":"Person","name":"sobolevn"},"datePublished":"2023-07-29T12:01:13Z","url":"https://github.com/python/mypy/issues/15775"}
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:65c80911-86dd-03e1-3373-9a829f370f6d current-catalog-service-hash 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 request-id AC64:5537E:2474B30:304B173:6B00504F html-safe-nonce 092d4c9a44606516be2d5f80d10fa449c2b6b50bb0042a643c4e3ebaac78b1c5 visitor-payload eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQzY0OjU1MzdFOjI0NzRCMzA6MzA0QjE3Mzo2QjAwNTA0RiIsInZpc2l0b3JfaWQiOiI4NzI2NDIwNzc3NDkyMDQxODA3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= visitor-hmac c4cbb2834a86661a3e4131c7a37b9c5f1ce708b4e4c06556f9d7d031cb1d9a8f hovercard-subject-tag issue:1827456383 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/15775/issue_layout twitter:image https://opengraph.githubassets.com/d16d30555d3ac2cd4d3d72a59163a262388fb1ebf926aaa67513094bd8153b81/python/mypy/issues/15775 twitter:card summary_large_image og:image https://opengraph.githubassets.com/d16d30555d3ac2cd4d3d72a59163a262388fb1ebf926aaa67513094bd8153b81/python/mypy/issues/15775 og:image:alt Python allows class definitions inside NamedTuple bodies: >>> from typing import NamedTuple >>> class A(NamedTuple): ... class B: ... ... >>> A.B og:image:width 1200 og:image:height 600 og:site_name GitHub og:type object og:author:username sobolevn hostname github.com expected-hostname github.com None f420f4996e6b1ff1ccd6d7683f8134f4b5f0f8a50124c210dbfe7490e5644abb 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 26e00df917aba0f128135dc073ea0c5e33a70d40 ui-target full theme-color #1e2327 color-scheme light dark react-app-name issues
URLs of crawlers that visited me.