Skip to content
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

Maximum recursion depth when using ParamSpec/Concatenate #15388

Closed
karlicoss opened this issue Jun 7, 2023 · 2 comments · Fixed by #15272
Closed

Maximum recursion depth when using ParamSpec/Concatenate #15388

karlicoss opened this issue Jun 7, 2023 · 2 comments · Fixed by #15272
Labels
crash topic-paramspec PEP 612, ParamSpec, Concatenate

Comments

@karlicoss
Copy link

karlicoss commented Jun 7, 2023

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

@karlicoss karlicoss added the crash label Jun 7, 2023
@JelleZijlstra JelleZijlstra added the topic-paramspec PEP 612, ParamSpec, Concatenate label Jun 7, 2023
@AlexWaygood
Copy link
Member

Haven't looked in depth, but this is probably the same thing as #15073 (cc. @A5rocks)

@A5rocks
Copy link
Contributor

A5rocks commented 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash topic-paramspec PEP 612, ParamSpec, Concatenate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants