ruff
c429ef84 - [ty] don't expand type aliases via type mappings unless necessary (#22241)

Commit
3 days ago
[ty] don't expand type aliases via type mappings unless necessary (#22241) ## Summary `apply_type_mapping` always expands type aliases and operates on the resulting types, which can lead to cluttered results due to excessive type alias expansion in places where it is not actually needed. Specifically, type aliases are expanded when displaying method signatures, because we use `TypeMapping::BindSelf` to get the method signature. ```python type Scalar = int | float type Array1d = list[Scalar] | tuple[Scalar] def f(x: Scalar | Array1d) -> None: pass reveal_type(f) # revealed: def f(x: Scalar | Array1d) -> None class Foo: def f(self, x: Scalar | Array1d) -> None: pass # should be `bound method Foo.f(x: Scalar | Array1d) -> None` reveal_type(Foo().f) # revealed: bound method Foo.f(x: int | float | list[int | float] | tuple[int | float]) -> None ``` In this PR, when type mapping is performed on a type alias, the expansion result without type mapping is compared with the expansion result after type mapping, and if the two are equivalent, the expansion is deemed redundant and canceled. ## Test Plan mdtest updated
Author
Parents
Loading