[ty] Fix normalization of unions containing instances parameterized with unions (#18112)

This commit is contained in:
Alex Waygood 2025-05-14 22:48:33 -04:00 committed by GitHub
parent 9aa6330bb1
commit c3a4992ae9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 49 additions and 17 deletions

View file

@ -73,5 +73,8 @@ def f(x: Any, y: Unknown, z: Any | str | int):
c = cast(Unknown, y)
reveal_type(c) # revealed: Unknown
d = cast(str | int | Any, z) # error: [redundant-cast]
d = cast(Unknown, x)
reveal_type(d) # revealed: Unknown
e = cast(str | int | Any, z) # error: [redundant-cast]
```

View file

@ -118,6 +118,23 @@ class R: ...
static_assert(is_equivalent_to(Intersection[tuple[P | Q], R], Intersection[tuple[Q | P], R]))
```
## Unions containing generic instances parameterized by unions
```toml
[environment]
python-version = "3.12"
```
```py
from ty_extensions import is_equivalent_to, static_assert
class A: ...
class B: ...
class Foo[T]: ...
static_assert(is_equivalent_to(A | Foo[A | B], Foo[B | A] | A))
```
## Callable
### Equivalent