[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:
David Peter 2025-07-23 10:14:20 +02:00 committed by GitHub
parent c281891b5c
commit b605c3e232
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 1 deletions

View file

@ -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))