mypy
mypy copied to clipboard
Segmentation fault for TypeVar("T", bound=Callable[..., "T"])
Crash Report
mypy runs into a segfault when using a TypeVar like this:
T = TypeVar("T", bound=Callable[..., "T"])
Traceback
Unfortunately, nothing useful shows up:
$ mypy --show-traceback /tmp/err.py
Segmentation fault
To Reproduce
$ mypy /tmp/err.py
Segmentation fault
from typing import TypeVar
from collections.abc import Callable
T = TypeVar("T", bound=Callable[..., "T"])
Your Environment
- Mypy version used: mypy 1.8.0 (compiled: yes)
- Mypy command-line flags:
mypy /tmp/err.py - Mypy configuration options from
mypy.ini(and other config files): none - Python version used: Python 3.11.7
- Operating system and version: Calculate Linux Desktop 23 Cinnamon (Distributor ID: Gentoo)
Here's the traceback if you use an uncompiled version of mypy from the master branch (RecursionErrors cause mypyc to segfault without a traceback):
Traceback
(venv) (master) % mypy -c 'from typing import TypeVar, Callable; T = TypeVar("T", bound=Callable[..., "T"])' --show-traceback
<string>:1: 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.10.0+dev.790e8a73d8671a41cae419b4ea07579bfb2bc292
Traceback (most recent call last):
File "/Users/alexw/dev/mypy/venv/bin/mypy", line 8, in <module>
sys.exit(console_entry())
File "/Users/alexw/dev/mypy/mypy/__main__.py", line 15, in console_entry
main()
File "/Users/alexw/dev/mypy/mypy/main.py", line 100, in main
res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
File "/Users/alexw/dev/mypy/mypy/main.py", line 182, in run_build
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
File "/Users/alexw/dev/mypy/mypy/build.py", line 192, in build
result = _build(
File "/Users/alexw/dev/mypy/mypy/build.py", line 266, in _build
graph = dispatch(sources, manager, stdout)
File "/Users/alexw/dev/mypy/mypy/build.py", line 2942, in dispatch
process_graph(graph, manager)
File "/Users/alexw/dev/mypy/mypy/build.py", line 3340, in process_graph
process_stale_scc(graph, scc, manager)
File "/Users/alexw/dev/mypy/mypy/build.py", line 3435, in process_stale_scc
mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
File "/Users/alexw/dev/mypy/mypy/semanal_main.py", line 93, in semantic_analysis_for_scc
process_top_levels(graph, scc, patches)
File "/Users/alexw/dev/mypy/mypy/semanal_main.py", line 220, in process_top_levels
deferred, incomplete, progress = semantic_analyze_target(
File "/Users/alexw/dev/mypy/mypy/semanal_main.py", line 349, in semantic_analyze_target
analyzer.refresh_partial(
File "/Users/alexw/dev/mypy/mypy/semanal.py", line 599, in refresh_partial
self.refresh_top_level(node)
File "/Users/alexw/dev/mypy/mypy/semanal.py", line 610, in refresh_top_level
self.accept(d)
File "/Users/alexw/dev/mypy/mypy/semanal.py", line 6588, in accept
node.accept(self)
File "/Users/alexw/dev/mypy/mypy/nodes.py", line 1310, in accept
return visitor.visit_assignment_stmt(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/semanal.py", line 2890, in visit_assignment_stmt
if self.process_typevar_declaration(s):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/semanal.py", line 4122, in process_typevar_declaration
res = self.process_typevar_parameters(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/semanal.py", line 4264, in process_typevar_parameters
tv_arg = self.get_typevarlike_argument("TypeVar", param_name, param_value, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/semanal.py", line 4315, in get_typevarlike_argument
analyzed = self.expr_to_analyzed_type(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/semanal.py", line 6624, in expr_to_analyzed_type
return self.anal_type(
^^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/semanal.py", line 6739, in anal_type
typ = typ.accept(a)
^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/types.py", line 964, in accept
return visitor.visit_unbound_type(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/typeanal.py", line 267, in visit_unbound_type
typ = self.visit_unbound_type_nonoptional(t, defining_literal)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/typeanal.py", line 407, in visit_unbound_type_nonoptional
special = self.try_analyze_special_unbound_type(t, fullname)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/typeanal.py", line 593, in try_analyze_special_unbound_type
return self.analyze_callable_type(t)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/typeanal.py", line 1386, in analyze_callable_type
return ret.accept(self)
^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/types.py", line 1979, in accept
return visitor.visit_callable_type(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/typeanal.py", line 1043, in visit_callable_type
variables=self.anal_var_defs(variables),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/typeanal.py", line 1734, in anal_var_defs
return [self.anal_var_def(vd) for vd in var_defs]
^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/typeanal.py", line 1724, in anal_var_def
upper_bound=var_def.upper_bound.accept(self),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/types.py", line 1979, in accept
<many lines...>
return visitor.visit_callable_type(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/typeanal.py", line 1043, in visit_callable_type
variables=self.anal_var_defs(variables),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/typeanal.py", line 1734, in anal_var_defs
return [self.anal_var_def(vd) for vd in var_defs]
^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/typeanal.py", line 1724, in anal_var_def
upper_bound=var_def.upper_bound.accept(self),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/types.py", line 1979, in accept
return visitor.visit_callable_type(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/typeanal.py", line 983, in visit_callable_type
with self.tvar_scope_frame():
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/contextlib.py", line 137, in __enter__
return next(self.gen)
^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/typeanal.py", line 1577, in tvar_scope_frame
self.tvar_scope = self.tvar_scope.method_frame()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/mypy/mypy/tvar_scope.py", line 90, in method_frame
return TypeVarLikeScope(self, False, None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded