Skip to content

Cannot resolve recursive/cyclic definitions (v0.991, Python 3.8/3.9) #14219

@bartfeenstra

Description

@bartfeenstra

Bug Report

Mypy fails to check recursive/cyclic type aliases, even with #731 being part of v0.991. However, this happens on Python 3.8 and 3.9 only (and possibly below), but not on 3.10 or 3.11.
Example:

RecursiveTypeAlias: TypeAlias = Union[bool, int, float, str, Sequence['RecursiveTypeAlias']]

for which mypy raises error: Cannot resolve name "RecursiveTypeAlias" (possible cyclic definition) [misc].

To Reproduce

Alternatively, clone https://github.com/bartfeenstra/mypy-type-alias and run tox.

Expected Behavior
Mypy not raising any errors for recursive/cyclig type aliases and correctly parsing them as it does on Python 3.10 and 3.11.

Actual Behavior
Mypy fails on recursive/cyclic type aliases with the error error: Cannot resolve name "RecursiveTypeAlias" (possible cyclic definition) [misc].

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions