Skip to content

Quoted type aliases not understood #846

@sterliakov

Description

@sterliakov

Summary

Check the following code:

from typing import TypeAlias

Foo: TypeAlias = "int | str"
Bar: TypeAlias = int | str

x: Foo = 0  # Fails
y: Bar = 0  # OK

Output of uvx ty check a.py --output-format concise (without any config files, in a fresh mktemp -d with the above snippet cat'd into a.py):

error[invalid-type-form] a.py:6:4: Variable of type `Literal["int | str"]` is not allowed in a type expression
Found 1 diagnostic

playground link

As per the spec, quotes should be ignored in the RHS, it is not a literal definition:)

This isn't a toy problem - quoted RHS is the most convenient way to define a recursive alias (at least prior to PEP695, but I'd personally use this on 3.12+ too) or make it dependent on TYPE_CHECKING-only imports.

Foo: TypeAlias = "int | Iterable[Foo]"

Version

0.0.1-alpha.14

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions