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

[1.11 regression] Infinite recursion with callables and follow imports skip #17954

Closed
Viicos opened this issue Oct 15, 2024 · 3 comments · Fixed by #17961
Closed

[1.11 regression] Infinite recursion with callables and follow imports skip #17954

Viicos opened this issue Oct 15, 2024 · 3 comments · Fixed by #17961
Labels

Comments

@Viicos
Copy link
Contributor

Viicos commented Oct 15, 2024

With pydantic_core installed, the following file:

from typing import Callable

from pydantic_core import core_schema

Recurse = Callable[[core_schema.CoreSchema, 'Walk'], core_schema.CoreSchema]
Walk = Callable[[core_schema.CoreSchema, Recurse], core_schema.CoreSchema]

Results in a segmentation fault on compiled version.

The end of the traceback using interpreted from master:

  ...
  File "/fakepath/lib/python3.12/site-packages/mypy/typetraverser.py", line 85, in visit_callable_type
    self.traverse_types(t.arg_types)
  File "/fakepath/lib/python3.12/site-packages/mypy/typetraverser.py", line 148, in traverse_types
    typ.accept(self)
  File "/fakepath/lib/python3.12/site-packages/mypy/types.py", line 410, in accept
    return visitor.visit_type_alias_type(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/fakepath/lib/python3.12/site-packages/mypy/messages.py", line 2754, in visit_type_alias_type
    get_proper_type(t).accept(self)
    ^^^^^^^^^^^^^^^^^^
  File "/fakepath/lib/python3.12/site-packages/mypy/types.py", line 3185, in get_proper_type
    typ = typ._expand_once()
          ^^^^^^^^^^^^^^^^^^
  File "/fakepath/lib/python3.12/site-packages/mypy/types.py", line 352, in _expand_once
    new_tp = self.alias.target.accept(InstantiateAliasVisitor(mapping))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/fakepath/lib/python3.12/site-packages/mypy/types.py", line 2018, in accept
    return visitor.visit_callable_type(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/fakepath/lib/python3.12/site-packages/mypy/expandtype.py", line 409, in visit_callable_type
    arg_types = self.expand_types(t.arg_types)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/fakepath/lib/python3.12/site-packages/mypy/expandtype.py", line 515, in expand_types
    a.append(t.accept(self))
             ^^^^^^^^^^^^^^
  File "/fakepath/lib/python3.12/site-packages/mypy/types.py", line 410, in accept
    return visitor.visit_type_alias_type(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/fakepath/lib/python3.12/site-packages/mypy/expandtype.py", line 510, in visit_type_alias_type
    return t.copy_modified(args=args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/fakepath/lib/python3.12/site-packages/mypy/types.py", line 443, in copy_modified
    return TypeAliasType(
           ^^^^^^^^^^^^^^
  File "/fakepath/lib/python3.12/site-packages/mypy/types.py", line 318, in __init__
RecursionError: maximum recursion depth exceeded

Your Environment

  • Mypy version used: 1.11.0 through 1.12.0
  • Python version used: 3.12
  • Mypy command: mypy t.py --config-file mypy.ini
  • Operating system and version: Ubuntu

Config file (the two config values are necessary to reproduce):

[mypy]
disallow_any_unimported = True

[mypy-pydantic_core.*]
follow_imports = skip
@Viicos Viicos added the crash label Oct 15, 2024
@hauntsaninja
Copy link
Collaborator

Bisects to #17495

@hauntsaninja hauntsaninja changed the title Segmentation fault (recursion limit reached) since mypy 1.11.0 with callables [1.11 regression] Infinite recursion with callables and follow imports skip Oct 15, 2024
@ilevkivskyi
Copy link
Member

Yeah, I was a bit worried this may happen, I will take this one.

JukkaL pushed a commit that referenced this issue Oct 16, 2024
Fixes #17954

People say something about cache invalidation being one of the hardest
problems...
@Viicos
Copy link
Contributor Author

Viicos commented Oct 16, 2024

Thanks for the quick fix!

hauntsaninja pushed a commit to hauntsaninja/mypy that referenced this issue Oct 18, 2024
…on#17961)

Fixes python#17954

People say something about cache invalidation being one of the hardest
problems...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants