[ty] Fix wrong inlay hints for overloaded function arguments#23179
[ty] Fix wrong inlay hints for overloaded function arguments#23179charliermarsh merged 2 commits intomainfrom
Conversation
Typing conformance resultsNo changes detected ✅ |
|
7cb8285 to
82a31c8
Compare
| /// | ||
| /// Falls back to arity-based matching if type-based resolution fails. | ||
| fn resolve_call_signature<'db>( | ||
| db: &'db dyn Db, |
There was a problem hiding this comment.
Rather than passing in db as a separate argument, I think you can just add let db = model.db(); as the first line of the function
| let callable_type = func_type | ||
| .try_upcast_to_callable(model.db()) | ||
| .map(|callables| callables.into_type(model.db()))?; |
There was a problem hiding this comment.
| let callable_type = func_type | |
| .try_upcast_to_callable(model.db()) | |
| .map(|callables| callables.into_type(model.db()))?; | |
| let callable_type = func_type.try_upcast_to_callable(db)?.into_type(db); |
| .bindings(model.db()) | ||
| .match_parameters(model.db(), &call_arguments); | ||
|
|
||
| let db = model.db(); |
There was a problem hiding this comment.
if you moved this assignment higher up in the function, you could replace four more model.db() calls with db
| let bindings = match &checked { | ||
| Ok(bindings) => bindings, | ||
| Err(err) => &err.1, | ||
| }; |
There was a problem hiding this comment.
nit: I'd use .unwrap_or_else() here
| .try_upcast_to_callable(model.db()) | ||
| .map(|callables| callables.into_type(model.db()))?; | ||
|
|
||
| let args = CallArguments::from_arguments_typed(&call_expr.arguments, |_, splatted_value| { |
There was a problem hiding this comment.
This is a pre-existing issue, but: I'm a bit confused about why the passed-in closure here needs to take 2 arguments. It looks like there are now two callsites of CallArguments::from_arguments_typed() on this PR branch, and both callsites pass in a closure that ignores the first argument passed into it
| let bindings = callable_type.bindings(db).match_parameters(db, &args); | ||
|
|
||
| // Extract the `Bindings` regardless of whether type checking succeeded or failed. | ||
| let checked = bindings.check_types(db, &args, TypeContext::default(), &[]); | ||
| let bindings = match &checked { | ||
| Ok(bindings) => bindings, | ||
| Err(err) => &err.1, | ||
| }; |
There was a problem hiding this comment.
nit
| let bindings = callable_type.bindings(db).match_parameters(db, &args); | |
| // Extract the `Bindings` regardless of whether type checking succeeded or failed. | |
| let checked = bindings.check_types(db, &args, TypeContext::default(), &[]); | |
| let bindings = match &checked { | |
| Ok(bindings) => bindings, | |
| Err(err) => &err.1, | |
| }; | |
| let bindings = callable_type | |
| .bindings(db) | |
| .match_parameters(db, &args) | |
| .check_types(db, &args, TypeContext::default(), &[]) | |
| .unwrap_or_else(|CallError(_, bindings)| *bindings); |
82a31c8 to
7f4f996
Compare
* main: (45 commits) [ty] Fix wrong inlay hints for overloaded function arguments (astral-sh#23179) [ty] Respect `@no_type_check` when combined with other decorators (astral-sh#23177) [ty] Use type context when inferring constructor argument types (astral-sh#23139) [`airflow`] Add ruff rules to catch deprecated attribute access from context key for Airflow 3.0 (`AIR301`) (astral-sh#22850) Support formatting `pycon` markdown code blocks (astral-sh#23112) Markdown formatting in LSP (astral-sh#23063) Instruct Claude to use comments more sparingly (astral-sh#23181) [`flake8-gettext`] Fix false negatives for plural argument of ngettext (`INT001`, `INT002`, `INT003`) (astral-sh#21078) [ty] Invoking goto-def on parentheses of a class constructor call takes you too constructor method [ty] Make goto definition on class constructor always go to class definition [ty] Assign lower completions ranking to deprecated functions and classes (astral-sh#23089) [ty] Fix parameter references across files via keyword args (astral-sh#23012) [ty] Exclude enclosing class for base completions (astral-sh#23141) [`pyupgrade`] Fix syntax error on string with newline escape and comment (`UP037`) (astral-sh#22968) [ty] Improve documentation for `expect_single_definition` method (astral-sh#23175) [ty] Configure check mode for all projects Add `home-assistant` to ecosystem projects (astral-sh#23132) Add tabbed shell completion documentation (astral-sh#23169) Bump typing conformance-suite pin (astral-sh#23174) [ty] Fix invalid diagnostic location for a sub-call to a specialized ParamSpec (astral-sh#23036) ...
Summary
Inlay hints for function call arguments were showing parameter names from the wrong overload variant because they only performed arity-based matching.
Closes astral-sh/ty#1985.