Skip to content

typing.TypeAliasType cannot be used to declare self-referential types #18252

@bzoracler

Description

@bzoracler

Bug Report, To Reproduce, & Actual Behaviour

See mypy Playground:

type T = dict[str, "T"]  # OK

from typing import TypeAliasType

T2 = TypeAliasType("T2", dict[str, "T2"])  # E: Cannot resolve name "T2" (possible cyclic definition)  [misc]

Expected Behavior

Self-referential type successfully declared

Your Environment

  • Mypy version used: 1.13.0
  • Mypy command-line flags: (none)
  • Mypy configuration options from mypy.ini (and other config files): (none)
  • Python version used: 3.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions