Closed
Description
Crash Report
Using current dev version of mypy (1.6.0+dev.4077dc6c4b87b273bfd4552d75faaafa6c016c25), with PEP646 experimental flag, the following code makes mypy crash
Traceback
$ /home/vscode/.local/bin/mypy --enable-incomplete-feature=TypeVarTuple --enable-incomplete-feature=Unpack test.py --show-traceback
test.py:14: error: "A" expects 1 type argument, but 2 given [type-arg]
test.py:14: 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://github.com/python/mypy/issues
version: 1.6.0+dev.4077dc6c4b87b273bfd4552d75faaafa6c016c25
Traceback (most recent call last):
File "/home/vscode/.local/bin/mypy", line 8, in <module>
sys.exit(console_entry())
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/__main__.py", line 15, in console_entry
main()
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/main.py", line 99, in main
res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/main.py", line 178, in run_build
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/build.py", line 189, in build
result = _build(
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/build.py", line 262, in _build
graph = dispatch(sources, manager, stdout)
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/build.py", line 2938, in dispatch
process_graph(graph, manager)
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/build.py", line 3336, in process_graph
process_stale_scc(graph, scc, manager)
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/build.py", line 3431, in process_stale_scc
mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/semanal_main.py", line 94, in semantic_analysis_for_scc
process_functions(graph, scc, patches)
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/semanal_main.py", line 252, in process_functions
process_top_level_function(
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/semanal_main.py", line 291, in process_top_level_function
deferred, incomplete, progress = semantic_analyze_target(
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/semanal_main.py", line 349, in semantic_analyze_target
analyzer.refresh_partial(
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/semanal.py", line 603, in refresh_partial
self.accept(node)
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/semanal.py", line 6487, in accept
node.accept(self)
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/nodes.py", line 790, in accept
return visitor.visit_func_def(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/semanal.py", line 833, in visit_func_def
self.analyze_func_def(defn)
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/semanal.py", line 867, in analyze_func_def
if self.found_incomplete_ref(tag) or has_placeholder(result):
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/semanal_shared.py", line 355, in has_placeholder
return typ.accept(HasPlaceholders())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/types.py", line 1929, in accept
return visitor.visit_callable_type(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/type_visitor.py", line 505, in visit_callable_type
args = self.query_types(t.arg_types)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/type_visitor.py", line 557, in query_types
return any(t.accept(self) for t in types)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/type_visitor.py", line 557, in <genexpr>
return any(t.accept(self) for t in types)
^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/types.py", line 397, in accept
return visitor.visit_type_alias_type(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/type_visitor.py", line 550, in visit_type_alias_type
return get_proper_type(t).accept(self)
^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/types.py", line 2986, in get_proper_type
typ = typ._expand_once()
^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/types.py", line 339, in _expand_once
new_tp = self.alias.target.accept(InstantiateAliasVisitor(mapping))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/types.py", line 2352, in accept
return visitor.visit_tuple_type(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/expandtype.py", line 406, in visit_tuple_type
items = self.expand_types_with_unpack(t.items)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/expandtype.py", line 394, in expand_types_with_unpack
unpacked_items = self.expand_unpack(item)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/mypy/expandtype.py", line 291, in expand_unpack
raise RuntimeError(f"Invalid type replacement to expand: {repl}")
RuntimeError: Invalid type replacement to expand: Unpack[builtins.tuple[Any, ...]]
test.py:14: : note: use --pdb to drop into pdb
To Reproduce
from __future__ import annotations
from typing import Generic, Tuple, reveal_type # noqa
from typing_extensions import TypeVarTuple, Unpack # noqa
T = TypeVarTuple("T")
class A(Tuple[Unpack[T]]): # noqa
...
def f(w: A[str, int]):
x, y = w
reveal_type(x)
reveal_type(y)
Your Environment
- Mypy version used: 1.6.0+dev.4077dc6c4b87b273bfd4552d75faaafa6c016c25
- Mypy command-line flags: --enable-incomplete-feature=TypeVarTuple --enable-incomplete-feature=Unpack
- Mypy configuration options from
mypy.ini
(and other config files): None - Python version used: 3.11.4
- Operating system and version: MacOS, but using Ubuntu devcontainer image