ruff
cb4fec21 - [ty] Pass the generic context through the decorator (#22544)

Commit
3 days ago
[ty] Pass the generic context through the decorator (#22544) ## Summary fixes: https://github.com/astral-sh/ty/issues/2336 fixes: https://github.com/astral-sh/ty/issues/2382 This PR fixes a bug where the generic context was not being passed through the decorator via the `ParamSpec` type variable. For example: ```py from typing import Callable def decorator[**P, R](f: Callable[P, R]) -> Callable[P, R]: ... @decorator def foo[T](x: T): ... foo(1) ``` This meant that after the decorator has been applied, the `Callable` corresponding to the `ParamSpec` type variable did not preserve the generic context from the decorated function, which lead to `foo` loosing the generic context. ## Test Plan Add new mdtest cases. ### Typing conformance result The false positive that's removed is correct. The true positives that are removed isn't correct but it's unrelated to this PR (related to https://github.com/astral-sh/ty/issues/623). The case is: ```py def accepts_callable(cb: t.Callable[P, R]) -> t.Callable[P, R]: return cb class Class9: def __init__(self, x: list[T], y: list[T]) -> None: ... r9 = accepts_callable(Class9) r9([1], [""]) # E ``` Here, the `r9` call has two arguments and the corresponding parameters have the _same_ type variable. Pyright specializes using the first argument and errors on the second argument while ty currently union the constraints i.e., `T: Unknown | int | str` (`Unknown` because `T` is inside a `list`).
Author
Parents
Loading