Title: Crash with forward reference in NamedTuple · Issue #3315 · python/mypy · GitHub
Open Graph Title: Crash with forward reference in NamedTuple · Issue #3315 · python/mypy
X Title: Crash with forward reference in NamedTuple · Issue #3315 · python/mypy
Description: Found this testing my production codebase against mypy master: (venv) jelle@devjelle:~/mypy$ cat testnt.py from typing import NamedTuple class A(NamedTuple): b: 'B' x: int class B: pass (venv) jelle@devjelle:~/mypy$ python -m mypy --show...
Open Graph Description: Found this testing my production codebase against mypy master: (venv) jelle@devjelle:~/mypy$ cat testnt.py from typing import NamedTuple class A(NamedTuple): b: 'B' x: int class B: pass (venv) jell...
X Description: Found this testing my production codebase against mypy master: (venv) jelle@devjelle:~/mypy$ cat testnt.py from typing import NamedTuple class A(NamedTuple): b: 'B' x: int class B: pass (ve...
Opengraph URL: https://github.com/python/mypy/issues/3315
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Crash with forward reference in NamedTuple","articleBody":"Found this testing my production codebase against mypy master:\r\n```\r\n(venv) jelle@devjelle:~/mypy$ cat testnt.py\r\nfrom typing import NamedTuple\r\n\r\nclass A(NamedTuple):\r\n b: 'B'\r\n x: int\r\n\r\nclass B:\r\n pass\r\n(venv) jelle@devjelle:~/mypy$ python -m mypy --show-traceback testnt.py \r\ntestnt.py:3: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.510-dev-09e7b124b82dae1207d9eac6805b64a98290015c\r\nTraceback (most recent call last):\r\n File \"/home/jelle/ans/venv64/lib/python3.6/runpy.py\", line 193, in _run_module_as_main\r\n \"__main__\", mod_spec)\r\n File \"/home/jelle/ans/venv64/lib/python3.6/runpy.py\", line 85, in _run_code\r\n exec(code, run_globals)\r\n File \"/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/__main__.py\", line 5, in \u003cmodule>\r\n main(None)\r\n File \"/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/main.py\", line 46, in main\r\n res = type_check_only(sources, bin_dir, options)\r\n File \"/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/main.py\", line 93, in type_check_only\r\n options=options)\r\n File \"/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/build.py\", line 188, in build\r\n graph = dispatch(sources, manager)\r\n File \"/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/build.py\", line 1595, in dispatch\r\n process_graph(graph, manager)\r\n File \"/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/build.py\", line 1838, in process_graph\r\n process_stale_scc(graph, scc, manager)\r\n File \"/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/build.py\", line 1931, in process_stale_scc\r\n graph[id].semantic_analysis()\r\n File \"/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/build.py\", line 1495, in semantic_analysis\r\n self.manager.semantic_analyzer.visit_file(self.tree, self.xpath, self.options)\r\n File \"/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/semanal.py\", line 257, in visit_file\r\n self.accept(d)\r\n File \"/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/semanal.py\", line 3279, in accept\r\n node.accept(self)\r\n File \"/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/nodes.py\", line 749, in accept\r\n return visitor.visit_class_def(self)\r\n File \"/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/semanal.py\", line 617, in visit_class_def\r\n with self.analyze_class_body(defn) as should_continue:\r\n File \"/home/jelle/ans/venv64/lib/python3.6/contextlib.py\", line 82, in __enter__\r\n return next(self.gen)\r\n File \"/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/semanal.py\", line 629, in analyze_class_body\r\n if self.analyze_namedtuple_classdef(defn):\r\n File \"/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/semanal.py\", line 819, in analyze_namedtuple_classdef\r\n defn.name, items, types, default_items)\r\n File \"/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/semanal.py\", line 2053, in build_namedtuple_typeinfo\r\n fallback = self.named_type('__builtins__.tuple', [join.join_type_list(types)])\r\n File \"/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/join.py\", line 388, in join_type_list\r\n joined = join_types(joined, t)\r\n File \"/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/join.py\", line 88, in join_types\r\n return t.accept(TypeJoinVisitor(s))\r\n File \"/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/types.py\", line 411, in accept\r\n return visitor.visit_instance(self)\r\n File \"/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/join.py\", line 141, in visit_instance\r\n return join_instances(t, self.s)\r\n File \"/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/join.py\", line 295, in join_instances\r\n return join_instances_via_supertype(s, t)\r\n File \"/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/join.py\", line 314, in join_instances_via_supertype\r\n assert best is not None\r\nAssertionError: \r\ntestnt.py:3: note: use --pdb to drop into pdb\r\n```\r\n\r\nHaven't tried yet to minimize this further. Hopefully we can get this fixed before the release.\r\n\r\nEdit: this also repros with TypedDict:\r\n```\r\nfrom mypy_extensions import TypedDict\r\n\r\nX = TypedDict('X', {'b': 'B', 'c': int})\r\n\r\nclass B: pass\r\n```","author":{"url":"https://github.com/JelleZijlstra","@type":"Person","name":"JelleZijlstra"},"datePublished":"2017-05-04T04:00:39Z","url":"https://github.com/python/mypy/issues/3315"}
| 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:0cac51e5-8af7-7883-67e4-965d4a1353f9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BA78:302FC:5F1EF3:7F2394:6B003376 |
| html-safe-nonce | 96fc0360537663e113ec9e403d3ad7375dbff52b6f6ea414b5a689652e45de29 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQTc4OjMwMkZDOjVGMUVGMzo3RjIzOTQ6NkIwMDMzNzYiLCJ2aXNpdG9yX2lkIjoiNjQ3ODMxODk0MzUzMzU0NDMxMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 47a23be73d907214844d9876738001a2671cddf2f9d0d6a06d4bf5094d7b28a5 |
| hovercard-subject-tag | issue:226172713 |
| 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/3315/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d43a3faceddd59135098e9b13b96ae1bd90bfbe68e1728ecd439d424933305b8/python/mypy/issues/3315 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d43a3faceddd59135098e9b13b96ae1bd90bfbe68e1728ecd439d424933305b8/python/mypy/issues/3315 |
| og:image:alt | Found this testing my production codebase against mypy master: (venv) jelle@devjelle:~/mypy$ cat testnt.py from typing import NamedTuple class A(NamedTuple): b: 'B' x: int class B: pass (venv) jell... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JelleZijlstra |
| 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