-
Notifications
You must be signed in to change notification settings - Fork 219
Closed
astral-sh/ruff
#23200Labels
Description
Summary
When a PEP 613 TypeAlias is created with a generic whose parameter is a stringified type annotation, ty mistakenly emits a invalid-type-form diagnostic and infers Unknown.
The correct behaviour is present for PEP 695 type aliases, or when non-string or fully string annotations are used.
from typing import TYPE_CHECKING, TypeAlias, Optional, reveal_type
class A: ...
type AliasA1 = Optional[A] # Okay
AliasA2: TypeAlias = Optional[A] # Okay
type AliasB1 = Optional["A"] # Okay
AliasB2: TypeAlias = Optional["A"] # Not okay
type AliasC1 = "Optional[A]" # Okay
AliasC2: TypeAlias = "Optional[A]" # Okay
def _(a1: AliasA1, a2: AliasA2, b1: AliasB1, b2: AliasB2, c1: AliasC1, c2: AliasC2) -> None: ...
# ^^^^^^^
# Variable of type `Literal["A"]` is not allowed in a type expression (invalid-type-form) [Ln 14, Col 50]Version
ty 0.0.15
Reactions are currently unavailable