mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:16 +00:00
[ty] Fix normalization of unions containing instances parameterized with unions (#18112)
This commit is contained in:
parent
9aa6330bb1
commit
c3a4992ae9
6 changed files with 49 additions and 17 deletions
|
@ -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]
|
||||
```
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue