Repository navigation
Maximum recursion depth when using ParamSpec/Concatenate #15388
Copy link
Copy link
Closed
Labels
Description
Crash Report
I've been trying to annotate some decorators using ParamSpec/Concatenate and got mypy to segfault. In particular was trying to improve type annotations for https://github.com/python/typeshed/blob/main/stubs/decorator/decorator.pyi -- currently they are a bit too generic
Traceback
No traceback on latest stable mypy, just segfault
If I use master on mypy playground I get INTERNAL_ERROR and this:
...
File "/layers/google.python.pip/pip/lib/python3.10/site-packages/mypy/expandtype.py", line 536, in expand_types
a.append(t.accept(self))
File "/layers/google.python.pip/pip/lib/python3.10/site-packages/mypy/types.py", line 1917, in accept
return visitor.visit_callable_type(self)
File "/layers/google.python.pip/pip/lib/python3.10/site-packages/mypy/expandtype.py", line 429, in visit_callable_type
arg_types = self.expand_types(t.arg_types)
File "/layers/google.python.pip/pip/lib/python3.10/site-packages/mypy/expandtype.py", line 536, in expand_types
a.append(t.accept(self))
File "/layers/google.python.pip/pip/lib/python3.10/site-packages/mypy/types.py", line 1917, in accept
return visitor.visit_callable_type(self)
File "/layers/google.python.pip/pip/lib/python3.10/site-packages/mypy/expandtype.py", line 382, in visit_callable_type
param_spec = t.param_spec()
File "/layers/google.python.pip/pip/lib/python3.10/site-packages/mypy/types.py", line 2035, in param_spec
prefix = Parameters(self.arg_types[:-2], self.arg_kinds[:-2], self.arg_names[:-2])
File "/layers/google.python.pip/pip/lib/python3.10/site-packages/mypy/types.py", line 1569, in __init__
super().__init__(line, column)
File "/layers/google.python.pip/pip/lib/python3.10/site-packages/mypy/types.py", line 225, in __init__
super().__init__(line, column)
RecursionError: maximum recursion depth exceeded while calling a Python object
To Reproduce
Reproduces in https://mypy-play.net/?mypy=master&python=3.11&flags=show-traceback
from typing import ParamSpec, Concatenate, TypeVar, Callable
TD = TypeVar('TD')
PD = ParamSpec('PD')
def wrapper(
caller: Callable[Concatenate[Callable[PD, TD], PD], TD]
) -> None:
return None
T = TypeVar('T')
P = ParamSpec('P')
def _wrapped(func: Callable[P, T], *args: P.args, **kwargs: P.kwargs) -> T:
return func(*args, **kwargs)
_wrapped = wrapper(_wrapped)
Your Environment
Segfaults on latest stable mypy (1.3.0) regardless python version (tried 3.10/3.11/3.12)
INTERNAL_ERROR on master mypy
Reactions are currently unavailable
Activity
AlexWaygood commentedon Jun 8, 2023
Haven't looked in depth, but this is probably the same thing as #15073 (cc. @A5rocks)
A5rocks commentedon Jun 9, 2023
The crash specifically also gets fixed by #15272 (yay 🎉) -- nvm I finally read through the example, mypy's behavior on it makes sense. Assign it to another variable name e.g.
wrapped = wrapper(_wrapped).Reconsider constraints involving parameter specifications (#15272)