ruff
173f2765 - [ty] Preserve lexical ParamSpec scope for returned Callable annotations (#24909)

Commit
147 days ago
[ty] Preserve lexical ParamSpec scope for returned Callable annotations (#24909) ## Summary This PR preserves the distinction between a function's "public" signature and the lexical type-parameter scope used inside the function body. As an example: ```python from typing import Callable, cast def make_callback[**P]() -> Callable[P, None]: local: Callable[P, None] = cast(Callable[P, None], object()) return local ``` `make_callback` returns a generic callable, and `P` belongs to that returned `Callable`, not to `make_callback` itself. But within `make_callback`, PEP 695 type parameters are still lexically in scope. Previously, our rescoping could remove `P` from the generic context too early, so annotations like `local: Callable[P, None]` would be checked against the wrong scope. We now look at the lexical signature for function body inference, while keeping the existing public signature for callers. Closes https://github.com/astral-sh/ty/issues/3316.
Author
Parents
Loading