Skip to content

0.55.0 regression: false positive invalid-literal for Literal of union of Annotated[Literal[_], _] #2633

@jorenham

Description

@jorenham

After upgrading Pyrefly to 0.55.0 in optype, a new invalid-literal error was reported in a test (src), that the four other four type-checkers seem to have no issue with.

The test is a bit convoluted, so I tried minimizing the repro, and

from typing import Annotated, Literal, TypeAlias

One: TypeAlias = Literal[1]
Two: TypeAlias = Annotated[Literal[2], "irrelevant"]
OneOrTwo: TypeAlias = One | Two

Spam1: TypeAlias = Literal[One, Two]            # no problem
Spam2: TypeAlias = Literal[One, Two, OneOrTwo]  # E: invalid-literal

sandbox

OneOrTwo is supposed to be equivalent to Literal[1, 2]. But Pyrefly does not seem to recognize it as a Literal type, because there's an Annotated involved -- replace the Two definiens with Literal[2] (i.e. unwrap the Annotated), and the error disappears.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions