[ty] Resolve TypeVars in call_signature_details parameter types#23149
Conversation
Typing conformance resultsNo changes detected ✅ |
|
655625a to
320026a
Compare
|
Fixed the CI failures and force-pushed:
|
|
FYI @dcreager |
|
@dcreager is out for the next week so we shouldn't wait for his review here. The generics stuff looks reasonable to me, but I'll assign this to @BurntSushi for review on the LSP side. |
Thanks for the review. I addressed your comment, resolved some merge conflicts that were reported on GitHub, and pushed the updates. |
Memory usage reportMemory usage unchanged ✅ |
|
@knutwannheden Can you rebase this on |
|
@BurntSushi The PR is already rebased. |
|
It looks like you merged |
|
I see. Let me fix that. |
|
I don't see any merge conflicts here. @BurntSushi maybe try refreshing the webpage? |
Previously, `call_signature_details` populated `parameter_types` from raw `param.annotated_type()`, which left function-level TypeVars unresolved. For example, calling a generic function `pair[T](a: T, b: T)` with a `str` argument would report both parameters as type `T` instead of `str`. This change adds a `check_types` pass after `match_parameters` to infer TypeVar specializations from the actual argument types at the call site. The inferred specialization is then applied to each parameter's annotated type via `apply_specialization`, which resolves TypeVars while preserving non-TypeVar annotations unchanged. Two changes are needed: - Switch from `from_arguments` to `from_arguments_typed` so argument types are available for TypeVar inference - Call `check_types_impl` and use `binding.specialization()` to apply the inferred specialization to annotated types
e4867d0 to
7b9b0ea
Compare
|
Now it is a single fast-forward commit. |
|
@AlexWaygood Weird. I did refresh too (a few times). Maybe GitHub hiccup? |
|
@knutwannheden Thank you! |

Previously,
call_signature_detailspopulatedparameter_typesfrom rawparam.annotated_type(), which left function-level TypeVars unresolved. For example, calling a generic functionpair[T](a: T, b: T)with astrargument would report both parameters as typeTinstead ofstr.This change adds a
check_typespass aftermatch_parametersto infer TypeVar specializations from the actual argument types at the call site. The inferred specialization is then applied to each parameter's annotated type viaapply_specialization, which resolves TypeVars while preserving non-TypeVar annotations unchanged.Two changes are needed:
from_argumentstofrom_arguments_typedso argument types are available for TypeVar inferencecheck_types_impland usebinding.specialization()to apply the inferred specialization to annotated typesAn alternative would be to add a separate
call_signature_details_with_resolved_typesfunction to avoid changing the existing behavior, but since resolved types are strictly more useful for consumers (signature help, completions, IDE tooling), updating the existing function seems preferable.