-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
"maximum semantic analysis iteration count reached" with TypeVar bound to recursive type definition #8320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for reporting! Recursive types are not supported, but at least it shouldn't crash. |
The problem appears to be that whatever check is used to detect recursive types does not run when analyzing type variables. This seems to happen when a type variable is bounded or constrained by a recursively-defined type. from typing import Union, TypeVar
R = Union['R']
T = TypeVar('T', bound=R) This generates the error with every generic type constructor I tried, as well as Traceback on the current master branch (d6c2c01)version: 0.770+dev.d6c2c01fd04043bff55222f1f43a9fe2e15c0ccf
Traceback (most recent call last):
File "venv/bin/mypy", line 10, in <module>
sys.exit(console_entry())
File "venv/.../mypy/__main__.py", line 8, in console_entry
main(None, sys.stdout, sys.stderr)
File "venv/.../mypy/main.py", line 89, in main
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
File "venv/.../mypy/build.py", line 165, in build
result = _build(
File "venv/.../mypy/build.py", line 234, in _build
graph = dispatch(sources, manager, stdout)
File "venv/.../mypy/build.py", line 2631, in dispatch
process_graph(graph, manager)
File "venv/.../mypy/build.py", line 2938, in process_graph
process_stale_scc(graph, scc, manager)
File "venv/.../mypy/build.py", line 3031, in process_stale_scc
mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
File "venv/.../mypy/semanal_main.py", line 83, in semantic_analysis_for_scc
check_type_arguments(graph, scc, errors)
File "venv/.../mypy/semanal_main.py", line 359, in check_type_arguments
state.tree.accept(analyzer)
File "/system_python/3.8/.../contextlib.py", line 131, in __exit__
self.gen.throw(type, value, traceback)
File "venv/.../mypy/build.py", line 1903, in wrap_context
yield
File "venv/.../mypy/semanal_main.py", line 359, in check_type_arguments
state.tree.accept(analyzer)
File "venv/.../mypy/nodes.py", line 294, in accept
return visitor.visit_mypy_file(self)
File "venv/.../mypy/semanal_typeargs.py", line 39, in visit_mypy_file
super().visit_mypy_file(o)
File "venv/.../mypy/traverser.py", line 35, in visit_mypy_file
d.accept(self)
File "venv/.../mypy/nodes.py", line 1062, in accept
return visitor.visit_assignment_stmt(self)
File "venv/.../mypy/mixedtraverser.py", line 64, in visit_assignment_stmt
super().visit_assignment_stmt(o)
File "venv/.../mypy/traverser.py", line 85, in visit_assignment_stmt
o.rvalue.accept(self)
File "venv/.../mypy/nodes.py", line 1544, in accept
return visitor.visit_call_expr(self)
File "venv/.../mypy/traverser.py", line 172, in visit_call_expr
o.analyzed.accept(self)
File "venv/.../mypy/nodes.py", line 2091, in accept
return visitor.visit_type_var_expr(self)
File "venv/.../mypy/mixedtraverser.py", line 40, in visit_type_var_expr
o.upper_bound.accept(self)
File "venv/.../mypy/types.py", line 794, in accept
return visitor.visit_instance(self)
File "venv/.../mypy/semanal_typeargs.py", line 82, in visit_instance
if not is_subtype(arg, tvar.upper_bound):
File "venv/.../mypy/subtypes.py", line 93, in is_subtype
return _is_subtype(left, right,
File "venv/.../mypy/subtypes.py", line 135, in _is_subtype
return left.accept(SubtypeVisitor(orig_right,
File "venv/.../mypy/types.py", line 1898, in accept
assert isinstance(visitor, SyntheticTypeVisitor)
AssertionError: |
The original example doesn't crash on master with
The weird example with |
I encountered what appears to be a bug when using a TypeVar bound to a recursive type definition.
Simplified example code:
I ran the command:
mypy remove_w.py --show-traceback
with no additional configuration file
Output:
The text was updated successfully, but these errors were encountered: