Title: Fallback type for namedtuple/NamedTuple has containing module as module name · Issue #4287 · python/mypy · GitHub
Open Graph Title: Fallback type for namedtuple/NamedTuple has containing module as module name · Issue #4287 · python/mypy
X Title: Fallback type for namedtuple/NamedTuple has containing module as module name · Issue #4287 · python/mypy
Description: Example: from typing import NamedTuple F = [('x', int)] A = NamedTuple('A', F) # List or tuple literal expected as the second argument to namedtuple() def f(a: A): reveal_type(a) # Revealed type is 'Tuple[, fallback=t.namedtuple]' The fi...
Open Graph Description: Example: from typing import NamedTuple F = [('x', int)] A = NamedTuple('A', F) # List or tuple literal expected as the second argument to namedtuple() def f(a: A): reveal_type(a) # Revealed type is...
X Description: Example: from typing import NamedTuple F = [('x', int)] A = NamedTuple('A', F) # List or tuple literal expected as the second argument to namedtuple() def f(a: A): reveal_type(a) # ...
Opengraph URL: https://github.com/python/mypy/issues/4287
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Fallback type for namedtuple/NamedTuple has containing module as module name","articleBody":"Example:\r\n```py\r\nfrom typing import NamedTuple\r\n\r\nF = [('x', int)]\r\nA = NamedTuple('A', F) # List or tuple literal expected as the second argument to namedtuple()\r\n\r\ndef f(a: A):\r\n reveal_type(a) # Revealed type is 'Tuple[, fallback=t.namedtuple]'\r\n```\r\nThe first error is expected. But when we silence it, we see that the fallback type generated in this case is not `collections.namedtuple` but `t.namedtuple` (`t.py` was the filename I used).\r\n\r\nThe problem is that the fallback type ends up in the incremental cache, resulting in tracebacks when incremental mode is used like this:\r\n```\r\nTraceback (most recent call last):\r\n File \"/usr/lib/python3.5/runpy.py\", line 184, in _run_module_as_main\r\n \"__main__\", mod_spec)\r\n File \"/usr/lib/python3.5/runpy.py\", line 85, in _run_code\r\n exec(code, run_globals)\r\n File \"/home/user/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/__main__.py\", line 11, in \u003cmodule>\r\n main(None)\r\n File \"/home/user/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/main.py\", line 66, in main\r\n res = type_check_only(sources, bin_dir, options)\r\n File \"/home/user/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/main.py\", line 119, in type_check_only\r\n options=options)\r\n File \"/home/user/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/build.py\", line 212, in build\r\n graph = dispatch(sources, manager)\r\n File \"/home/user/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/build.py\", line 1939, in dispatch\r\n process_graph(graph, manager)\r\n File \"/home/user/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/build.py\", line 2219, in process_graph\r\n process_fresh_scc(graph, prev_scc, manager)\r\n File \"/home/user/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/build.py\", line 2296, in process_fresh_scc\r\n graph[id].fix_cross_refs()\r\n File \"/home/user/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/build.py\", line 1656, in fix_cross_refs\r\n self.manager.options.quick_and_dirty)\r\n File \"/home/user/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/fixup.py\", line 22, in fixup_module_pass_one\r\n node_fixer.visit_symbol_table(tree.names)\r\n File \"/home/user/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/fixup.py\", line 84, in visit_symbol_table\r\n self.quick_and_dirty)\r\n File \"/home/user/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/fixup.py\", line 284, in lookup_qualified_stnode\r\n assert key in names, \"Cannot find %s for %s\" % (key, name)\r\nAssertionError: Cannot find namedtuple for metaserver.lib.deletion_filter.namedtuple\r\n```","author":{"url":"https://github.com/gvanrossum","@type":"Person","name":"gvanrossum"},"datePublished":"2017-11-28T00:46:36Z","url":"https://github.com/python/mypy/issues/4287"}
| 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:e1e39bb2-6208-6bb0-20a0-2de4c090a26d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C494:2B9B04:303BEA1:3FDEBC6:6B002F49 |
| html-safe-nonce | c669531a40e44ff11718cf9789ad18e3922afc2168802436b969e338b1a35765 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNDk0OjJCOUIwNDozMDNCRUExOjNGREVCQzY6NkIwMDJGNDkiLCJ2aXNpdG9yX2lkIjoiODgxNDI1Nzg3NTIxNzAzNTA4MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d24aeede1c526bb417690945bf54983f72d92be09489432fe38dabde5b1ed2e9 |
| hovercard-subject-tag | issue:277220208 |
| 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/4287/issue_layout |
| twitter:image | https://opengraph.githubassets.com/72c1ed31184cecddc391ff7932e10fc23f8058a6fa4d27b2904e651caedd7ce0/python/mypy/issues/4287 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/72c1ed31184cecddc391ff7932e10fc23f8058a6fa4d27b2904e651caedd7ce0/python/mypy/issues/4287 |
| og:image:alt | Example: from typing import NamedTuple F = [('x', int)] A = NamedTuple('A', F) # List or tuple literal expected as the second argument to namedtuple() def f(a: A): reveal_type(a) # Revealed type is... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gvanrossum |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width