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

INTERNAL ERROR: maximum semantic analysis iteration count reached on self-referential union #17132

Closed
kmurphy4 opened this issue Apr 17, 2024 · 1 comment · Fixed by #17350
Closed
Labels
crash topic-recursive-types topic-type-alias TypeAlias and other type alias issues

Comments

@kmurphy4
Copy link

Crash Report

Under some specific conditions, mypy crashes when creating type aliases for unions with self-referential variants.

Specifically, both of these work fine:

X: ty.TypeAlias = ty.Union[
    ty.Set["X"],
    ty.Sequence["X"],
]

Y: ty.TypeAlias = ty.Union[
    ty.Sequence[ty.Optional["Y"]],
]

but this crashes:

Z: ty.TypeAlias = ty.Union[
    ty.Set["Z"],
    ty.Sequence[ty.Optional["Z"]],
]

with

main.py: error: INTERNAL ERROR: maximum semantic analysis iteration count reached

To Reproduce

https://mypy-play.net/?mypy=1.9.0&python=3.12&flags=show-traceback&gist=5f48179cab35cd594aca11d797bf530d

@ilevkivskyi
Copy link
Member

It is interesting that it looks like a slightly different version

Z = ty.Union[
    ty.Set[ty.Optional["Z"]],
    ty.Sequence[ty.Optional["Z"]],
]

hangs indefinitely, while eating memory.

@AlexWaygood AlexWaygood added the topic-type-alias TypeAlias and other type alias issues label Jun 9, 2024
ilevkivskyi added a commit that referenced this issue Jun 9, 2024
Fixes #17132

Fix is trivial, we don't need that extra `get_proper_type()`.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash topic-recursive-types topic-type-alias TypeAlias and other type alias issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants