-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
NotImplementedError crash on mutually recursive TypeVarTuple type aliases #21125
Copy link
Copy link
Open
Labels
crashtopic-pep-646PEP 646 (TypeVarTuple, Unpack)PEP 646 (TypeVarTuple, Unpack)topic-pep-695Issues related to PEP 695 syntaxIssues related to PEP 695 syntaxtopic-recursive-types
Description
Crash Report
I wanted to make an infinitely expanding tuple, ran into the error: Invalid recursive alias: a tuple item of itself safeguard, and tried to get around it with mutual recursion.
Traceback
Collapsed for readability
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "Scripts\mypy.exe\__main__.py", line 10, in <module>
sys.exit(console_entry())
File "Lib\site-packages\mypy\__main__.py", line 15, in console_entry
main()
File "Lib\site-packages\mypy\main.py", line 141, in main
res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
File "Lib\site-packages\mypy\main.py", line 225, in run_build
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
File "Lib\site-packages\mypy\build.py", line 391, in build
result = build_inner(
File "Lib\site-packages\mypy\build.py", line 488, in build_inner
graph = dispatch(sources, manager, stdout)
File "Lib\site-packages\mypy\build.py", line 3754, in dispatch
process_graph(graph, manager)
File "Lib\site-packages\mypy\build.py", line 4206, in process_graph
done, still_working, results = manager.wait_for_done(graph)
File "Lib\site-packages\mypy\build.py", line 1208, in wait_for_done
process_stale_scc(graph, next_scc, self)
File "Lib\site-packages\mypy\build.py", line 4371, in process_stale_scc
mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
File "Lib\site-packages\mypy\semanal_main.py", line 91, in semantic_analysis_for_scc
process_top_levels(graph, scc, patches)
File "Lib\site-packages\mypy\semanal_main.py", line 200, in process_top_levels
deferred, incomplete, progress = semantic_analyze_target(
File "Lib\site-packages\mypy\semanal_main.py", line 380, in semantic_analyze_target
analyzer.refresh_partial(
File "Lib\site-packages\mypy\semanal.py", line 701, in refresh_partial
self.refresh_top_level(node)
File "Lib\site-packages\mypy\semanal.py", line 730, in refresh_top_level
self.accept(d)
File "Lib\site-packages\mypy\semanal.py", line 7710, in accept
node.accept(self)
~~~~~~~~~~~^^^^^^
File "Lib\site-packages\mypy\nodes.py", line 2162, in accept
return visitor.visit_type_alias_stmt(self)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "Lib\site-packages\mypy\semanal.py", line 5695, in visit_type_alias_stmt
res, alias_tvars, depends_on, indexed = self.analyze_alias(
~~~~~~~~~~~~~~~~~~^
s.name.name,
^^^^^^^^^^^^
...<4 lines>...
python_3_12_type_alias=True,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "Lib\site-packages\mypy\semanal.py", line 4017, in analyze_alias
rvalue.accept(self)
~~~~~~~~~~~~~^^^^^^
File "Lib\site-packages\mypy\nodes.py", line 2533, in accept
return visitor.visit_index_expr(self)
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "Lib\site-packages\mypy\semanal.py", line 6216, in visit_index_expr
self.analyze_type_application(expr)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "Lib\site-packages\mypy\semanal.py", line 6222, in analyze_type_application
types = self.analyze_type_application_args(expr)
File "Lib\site-packages\mypy\semanal.py", line 6301, in analyze_type_application_args
flattened_items = flatten_nested_tuples(types)
File "Lib\site-packages\mypy\types.py", line 4211, in flatten_nested_tuples
p_type = get_proper_type(typ.type)
File "Lib\site-packages\mypy\types.py", line 3649, in get_proper_type
typ = typ._expand_once()
File "Lib\site-packages\mypy\types.py", line 382, in _expand_once
return self.alias.target.accept(InstantiateAliasVisitor(mapping))
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "Lib\site-packages\mypy\types.py", line 2818, in accept
return visitor.visit_tuple_type(self)
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "Lib\site-packages\mypy\expandtype.py", line 537, in visit_tuple_type
items = self.expand_type_list_with_unpack(t.items)
File "Lib\site-packages\mypy\expandtype.py", line 522, in expand_type_list_with_unpack
items.append(item.accept(self))
~~~~~~~~~~~^^^^^^
File "Lib\site-packages\mypy\types.py", line 1237, in accept
return visitor.visit_unpack_type(self)
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "Lib\site-packages\mypy\expandtype.py", line 387, in visit_unpack_type
return UnpackType(t.type.accept(self))
~~~~~~~~~~~~~^^^^^^
File "Lib\site-packages\mypy\types.py", line 418, in accept
return visitor.visit_type_alias_type(self)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "Lib\site-packages\mypy\expandtype.py", line 609, in visit_type_alias_type
args = self.expand_type_list_with_unpack(t.args)
File "Lib\site-packages\mypy\expandtype.py", line 522, in expand_type_list_with_unpack
items.append(item.accept(self))
~~~~~~~~~~~^^^^^^
File "Lib\site-packages\mypy\types.py", line 998, in accept
return visitor.visit_type_var_tuple(self)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "Lib\site-packages\mypy\expandtype.py", line 375, in visit_type_var_tuple
raise NotImplementedError
NotImplementedError:To Reproduce
https://mypy-play.net/?gist=d6bb4e3d5ec8b07b5441407ee428204d
type A[*TS] = tuple[*B[TS]]
type B[*TS] = tuple[*A[TS]]Powershell command used
PS ~\Downloads> uvx mypy@https://github.com/python/mypy.git --show-traceback -c @'
type A[*TS] = tuple[*B[TS]]
type B[*TS] = tuple[*A[TS]]
'@ > output.txtYour Environment
- Mypy version used: Current master
- Mypy command-line flags:
--show-traceback -c "code" - Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.14? Whatever
uvxdoes. - Operating system and version: Windows 11
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
crashtopic-pep-646PEP 646 (TypeVarTuple, Unpack)PEP 646 (TypeVarTuple, Unpack)topic-pep-695Issues related to PEP 695 syntaxIssues related to PEP 695 syntaxtopic-recursive-types