Title: Crash on code mixing instances and type typed variables · Issue #20526 · python/mypy · GitHub
Open Graph Title: Crash on code mixing instances and type typed variables · Issue #20526 · python/mypy
X Title: Crash on code mixing instances and type typed variables · Issue #20526 · python/mypy
Description: Crash Report INTERNAL ERROR Traceback mwe-mypy2.py:19: error: INTERNAL ERROR -- Please try using mypy master on GitHub: https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build Please report a bug at https:...
Open Graph Description: Crash Report INTERNAL ERROR Traceback mwe-mypy2.py:19: error: INTERNAL ERROR -- Please try using mypy master on GitHub: https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-...
X Description: Crash Report INTERNAL ERROR Traceback mwe-mypy2.py:19: error: INTERNAL ERROR -- Please try using mypy master on GitHub: https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-...
Opengraph URL: https://github.com/python/mypy/issues/20526
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Crash on code mixing instances and type typed variables","articleBody":"\u003c!--\n Use this form only if mypy reports an \"INTERNAL ERROR\" and/or gives a traceback.\n Please include the traceback and all other messages below (use `mypy --show-traceback`).\n-->\n\n**Crash Report**\n\nINTERNAL ERROR\n\n**Traceback**\n\n```python-traceback\nmwe-mypy2.py:19: error: INTERNAL ERROR -- Please try using mypy master on GitHub:\nhttps://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build\nPlease report a bug at https://github.com/python/mypy/issues\nversion: 1.20.0+dev.56c33f251cb6b3791297fdaa57453d4afaa8c4dc\nTraceback (most recent call last):\n File \"/home/.../.venv/bin/mypy\", line 8, in \u003cmodule>\n sys.exit(console_entry())\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/__main__.py\", line 15, in console_entry\n main()\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/main.py\", line 135, in main\n res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/main.py\", line 219, in run_build\n res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/build.py\", line 320, in build\n result = build_inner(\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/build.py\", line 417, in build_inner\n graph = dispatch(sources, manager, stdout)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/build.py\", line 3178, in dispatch\n process_graph(graph, manager)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/build.py\", line 3588, in process_graph\n done, still_working, results = manager.wait_for_done(graph)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/build.py\", line 1070, in wait_for_done\n process_stale_scc(graph, next_scc, self)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/build.py\", line 3752, in process_stale_scc\n graph[id].type_check_first_pass()\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/build.py\", line 2543, in type_check_first_pass\n self.type_checker().check_first_pass()\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checker.py\", line 530, in check_first_pass\n self.accept(d)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checker.py\", line 641, in accept\n stmt.accept(self)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/nodes.py\", line 1004, in accept\n return visitor.visit_func_def(self)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checker.py\", line 1198, in visit_func_def\n self._visit_func_def(defn)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checker.py\", line 1202, in _visit_func_def\n self.check_func_item(defn, name=defn.name)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checker.py\", line 1237, in check_func_item\n self.check_func_def(defn, typ, name, allow_empty)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checker.py\", line 1510, in check_func_def\n self.accept(item.body)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checker.py\", line 641, in accept\n stmt.accept(self)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/nodes.py\", line 1582, in accept\n return visitor.visit_block(self)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checker.py\", line 3159, in visit_block\n self.accept(s)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checker.py\", line 641, in accept\n stmt.accept(self)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/nodes.py\", line 1669, in accept\n return visitor.visit_assignment_stmt(self)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checker.py\", line 3212, in visit_assignment_stmt\n self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checker.py\", line 3387, in check_assignment\n rvalue_type, lvalue_type = self.check_simple_assignment(\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checker.py\", line 4668, in check_simple_assignment\n rvalue_type = self.expr_checker.accept(\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checkexpr.py\", line 6081, in accept\n typ = self.accept_maybe_cache(node, type_context=type_context)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checkexpr.py\", line 6116, in accept_maybe_cache\n typ = node.accept(self)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/nodes.py\", line 2298, in accept\n return visitor.visit_call_expr(self)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checkexpr.py\", line 508, in visit_call_expr\n return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checkexpr.py\", line 645, in visit_call_expr_inner\n ret_type = self.check_call_expr_with_callee_type(\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checkexpr.py\", line 1495, in check_call_expr_with_callee_type\n ret_type, callee_type = self.check_call(\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checkexpr.py\", line 1588, in check_call\n return self.check_callable_call(\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checkexpr.py\", line 1799, in check_callable_call\n arg_types = self.infer_arg_types_in_context(callee, args, arg_kinds, formal_to_actual)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checkexpr.py\", line 1973, in infer_arg_types_in_context\n res[ai] = self.accept(args[ai], arg_type)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checkexpr.py\", line 6083, in accept\n typ = node.accept(self) # r-value type, when interpreted as a value expression\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/nodes.py\", line 2198, in accept\n return visitor.visit_name_expr(self)\n ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checkexpr.py\", line 357, in visit_name_expr\n narrowed = self.narrow_type_from_binder(e, result)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/checkexpr.py\", line 6394, in narrow_type_from_binder\n narrowed = narrow_declared_type(known_type, restriction)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/meet.py\", line 141, in narrow_declared_type\n narrow_declared_type(d, n)\n ~~~~~~~~~~~~~~~~~~~~^^^^^^\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/meet.py\", line 222, in narrow_declared_type\n return meet_types(original_declared, original_narrowed)\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/meet.py\", line 113, in meet_types\n return t.accept(TypeMeetVisitor(s))\n ~~~~~~~~^^^^^^^^^^^^^^^^^^^^\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/types.py\", line 2846, in accept\n return visitor.visit_tuple_type(self)\n ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/meet.py\", line 1079, in visit_tuple_type\n return t.copy_modified(items=[meet_types(it, self.s.args[0]) for it in t.items])\n ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^mwe-mypy2.py:19: : note: use --pdb to drop into pdb\n\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/meet.py\", line 113, in meet_types\n return t.accept(TypeMeetVisitor(s))\n ~~~~~~~~^^^^^^^^^^^^^^^^^^^^\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/types.py\", line 3416, in accept\n return visitor.visit_union_type(self)\n ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/meet.py\", line 793, in visit_union_type\n meets = [meet_types(x, self.s) for x in t.items]\n ~~~~~~~~~~^^^^^^^^^^^\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/meet.py\", line 113, in meet_types\n return t.accept(TypeMeetVisitor(s))\n ~~~~~~~~^^^^^^^^^^^^^^^^^^^^\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/types.py\", line 1250, in accept\n return visitor.visit_unpack_type(self)\n ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^\n File \"/home/.../.venv/lib/python3.13/site-packages/mypy/meet.py\", line 845, in visit_unpack_type\n raise NotImplementedError\nNotImplementedError: \n```\n\n**To Reproduce**\n\n```python\nfrom typing import Hashable, cast\n\ntype Key[K: Hashable] = K | type[K]\ntype TP[K: Hashable] = tuple[Key[K], ...]\ntype Value[V] = V | type[V] | None\ntype T[K: Hashable, V] = tuple[*TP[K], Value[V]]\n\ndef f[K, V](one: TP[K] | T[K, V], other: TP[K] | T[K, V]) -> TP[K] | T[K, V] | None:\n if len(one) \u003c len(other):\n return None\n if one[:len(other)] != other:\n return None\n return cast(TP[K] | T[K, V], one[len(other):])\n\ndef g[K, V](one: TP[K] | T[K, V], other: TP[K] | T[K, V]) -> int | None:\n d: TP[K] | T[K, V] | None = f(one, other)\n if d is None:\n return None\n n: int = len(d)\n return n\n```\n\nand then run `mypy` on it.\n\n**Your Environment**\n\n\u003c!-- Include as many relevant details about the environment you experienced the bug in -->\n\n- Mypy version used: mypy 1.20.0+dev.56c33f251cb6b3791297fdaa57453d4afaa8c4dc (compiled: no)\n- Mypy command-line flags: `--show-traceback`\n- Mypy configuration options from `mypy.ini` (and other config files):\n- Python version used: Python 3.13.5\n- Operating system and version: 6.12.57+deb13-amd64 `#1` SMP PREEMPT_DYNAMIC Debian 6.12.57-1 (2025-11-05) x86_64 GNU/Linux\n\n\u003c!--\nYou can freely edit this text, please remove all the lines\nyou believe are unnecessary.\n-->\n","author":{"url":"https://github.com/guillonb","@type":"Person","name":"guillonb"},"datePublished":"2026-01-05T20:13:22Z","url":"https://github.com/python/mypy/issues/20526"}
| 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:b4fdf614-5e2d-dae5-6330-0d304fe4efff |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DA50:3E7030:2A1D02:38C35C:6B0025B7 |
| html-safe-nonce | dc5b7bcaf7af1c96f039001f982b8797d48ca8b74c45ab4a5cbdaec0fcbc56c5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQTUwOjNFNzAzMDoyQTFEMDI6MzhDMzVDOjZCMDAyNUI3IiwidmlzaXRvcl9pZCI6IjkwNDE2ODAxNzIwODgxMjk4MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | da9a2a0bbf1dae67e3b13b697e79ed80b2f75334eb6605feaca249ca105cdd40 |
| hovercard-subject-tag | issue:3782737732 |
| 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/20526/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1971281a5e3eab3b480ee0b5151385051493c8628ab8bedb0206cf75a0072a9a/python/mypy/issues/20526 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1971281a5e3eab3b480ee0b5151385051493c8628ab8bedb0206cf75a0072a9a/python/mypy/issues/20526 |
| og:image:alt | Crash Report INTERNAL ERROR Traceback mwe-mypy2.py:19: error: INTERNAL ERROR -- Please try using mypy master on GitHub: https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | guillonb |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width