-
Notifications
You must be signed in to change notification settings - Fork 216
Closed
astral-sh/ruff
#19502Labels
bugSomething isn't workingSomething isn't workingenumstype propertiessubtyping, assignability, equivalence, and moresubtyping, assignability, equivalence, and more
Description
Summary
from enum import Enum
from ty_extensions import static_assert, is_equivalent_to
from typing import Literal, reveal_type, Protocol
class Foo(Enum):
X = 1
static_assert(
is_equivalent_to(
tuple[Foo] | int | str,
str | int | tuple[Literal[Foo.X]]
)
)
class Bar(Protocol):
a: Foo
class Baz(Protocol):
a: Literal[Foo.X]
static_assert(is_equivalent_to(Bar, Baz))Both these static_assert calls fail currently, but they should both succeed. I think this should be easily fixable by fiddling with the implementation of Type::normalized() for enums: either we normalize Literal[Foo.X] to Foo if the enum only has a single member, or we normalize Foo to Literal[Foo.X] if Foo only has a single member.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingenumstype propertiessubtyping, assignability, equivalence, and moresubtyping, assignability, equivalence, and more