mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 05:44:56 +00:00
[ty] Normalize single-member enums to their instance type (#19502)
## Summary Fixes https://github.com/astral-sh/ty/issues/874 Labeling this as `internal`, since we haven't released the enum-expansion feature. ## Test Plan New Markdown tests
This commit is contained in:
parent
c281891b5c
commit
b605c3e232
3 changed files with 30 additions and 1 deletions
|
@ -13,7 +13,7 @@ materializations of `B`, and all materializations of `B` are also materializatio
|
|||
### Fully static
|
||||
|
||||
```py
|
||||
from typing_extensions import Literal, LiteralString, Never
|
||||
from typing_extensions import Literal, LiteralString, Protocol, Never
|
||||
from ty_extensions import Unknown, is_equivalent_to, static_assert, TypeOf, AlwaysTruthy, AlwaysFalsy
|
||||
from enum import Enum
|
||||
|
||||
|
@ -43,6 +43,16 @@ static_assert(is_equivalent_to(Literal[Single.VALUE], Single))
|
|||
static_assert(is_equivalent_to(Single, Literal[Single.VALUE]))
|
||||
static_assert(is_equivalent_to(Literal[Single.VALUE], Literal[Single.VALUE]))
|
||||
|
||||
static_assert(is_equivalent_to(tuple[Single] | int | str, str | int | tuple[Literal[Single.VALUE]]))
|
||||
|
||||
class Protocol1(Protocol):
|
||||
a: Single
|
||||
|
||||
class Protocol2(Protocol):
|
||||
a: Literal[Single.VALUE]
|
||||
|
||||
static_assert(is_equivalent_to(Protocol1, Protocol2))
|
||||
|
||||
static_assert(is_equivalent_to(Never, Never))
|
||||
static_assert(is_equivalent_to(AlwaysTruthy, AlwaysTruthy))
|
||||
static_assert(is_equivalent_to(AlwaysFalsy, AlwaysFalsy))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue