Skip to content

Conversation

@dcreager
Copy link
Member

@dcreager dcreager commented Jul 14, 2025

We previously had separate CallArguments and CallArgumentTypes types in support of our two-phase call binding logic. CallArguments would store only the arity/kind of each argument (positional, keyword, variadic, etc). We then performed parameter matching using only this arity/kind information, and then infered the type of each argument, placing the result of this second phase into a new CallArgumentTypes.

In #18996, we will need to infer the types of splatted arguments before performing parameter matching, since we need to know the argument type to accurately infer its length, which informs how many parameters the splatted argument is matched against.

That makes this separation of Rust types no longer useful. This PR merges everything back into a single CallArguments. In the case where we are performing two-phase call binding, the types will be initialized to None, and updated to the actual argument type during the second check_types phase.

[This is a refactoring in support of fixing the merge conflicts on #18996. I've pulled this out into a separate PR to make it easier to review in isolation.]

@dcreager dcreager added internal An internal refactor or improvement ty Multi-file analysis & type inference labels Jul 14, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jul 14, 2025

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@carljm
Copy link
Contributor

carljm commented Jul 14, 2025

Haven't looked at the code here yet, but I'm curious if defaulting to Type::Unknown is the best option here, vs using an Option<Type<'db>> Rust type? It seems like we might at some point regret the semantic muddiness of the former, where in principle Type::Unknown could mean "we haven't tried to infer any type for this argument yet", or it could equally well mean "we inferred a type for this argument, and the type that we found is "Unknown".

@dcreager
Copy link
Member Author

Haven't looked at the code here yet, but I'm curious if defaulting to Type::Unknown is the best option here, vs using an Option<Type<'db>> Rust type? It seems like we might at some point regret the semantic muddiness of the former, where in principle Type::Unknown could mean "we haven't tried to infer any type for this argument yet", or it could equally well mean "we inferred a type for this argument, and the type that we found is "Unknown".

Yeah I started that way but it was shaping up to be a much more invasive change, especially in the argument expansion code. The only thing we'd use that distinction for at the moment is to verify that we've already inferred the type of a splatted argument, like here.

Rather, I think a better approach in the spirit of your suggestion would be to keep separate CallArguments and CallArgumentTypes, but where the first has a Vec<Option<Type<'db>>> and the second has a Vec<Type<'db>>. (Maybe the types would deserve different names at that point? CallArgumentsBuilder and CallArguments?)

@dcreager
Copy link
Member Author

Yeah I started that way but it was shaping up to be a much more invasive change, especially in the argument expansion code.

Tried it again and with some cleanup I had done in the argument expansion code it looks better on the second attempt! Done

Copy link
Member

@dhruvmanila dhruvmanila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!

@sharkdp sharkdp removed their request for review July 15, 2025 09:13
dcreager added 6 commits July 15, 2025 09:53
* main:
  [`pylint`] Extend invalid string character rules to include t-strings (#19355)
  Make TC010 docs example more realistic (#19356)
  Move RDJSON rendering to `ruff_db` (#19293)
  [`flake8-use-pathlib`] Skip single dots for `invalid-pathlib-with-suffix` (`PTH210`) on versions >= 3.14 (#19331)
  [`ruff`] Allow `strict` kwarg when checking for `starmap-zip` (`RUF058`) in Python 3.14+ (#19333)
  [ty] Reduce false positives for `TypedDict` types (#19354)
  [ty] Remove `ConnectionInitializer` (#19353)
  [ty] Use `Type::string_literal()` more (#19352)
  [ty] Add ecosystem-report workflow (#19349)
  [ty] Make use of salsa `Lookup` when interning values (#19347)
  [ty] Sync vendored typeshed stubs (#19345)
  [`pylint`] Make example error out-of-the-box (`PLE2502`) (#19272)
  [`pydoclint`] Fix `SyntaxError` from fixes with line continuations (`D201`, `D202`) (#19246)
@AlexWaygood AlexWaygood removed their request for review July 15, 2025 14:03
@dcreager dcreager merged commit f4d0273 into main Jul 15, 2025
37 checks passed
@dcreager dcreager deleted the dcreager/merge-arguments branch July 15, 2025 14:21
dcreager added a commit that referenced this pull request Jul 15, 2025
* main:
  [ty] Combine CallArguments and CallArgumentTypes (#19337)
  Move Pylint rendering to `ruff_db` (#19340)
UnboundVariable pushed a commit to UnboundVariable/ruff that referenced this pull request Jul 15, 2025
…finition

* 'main' of https://github.com/astral-sh/ruff: (39 commits)
  [ty] Sync vendored typeshed stubs (astral-sh#19368)
  Fix typeshed-sync workflow (astral-sh#19367)
  Rework typeshed-sync workflow to also add docstrings for Windows- and MacOS-specific APIs (astral-sh#19360)
  [ty] Allow `-qq` for silent output mode (astral-sh#19366)
  [ty] Allow `-q` short alias for `--quiet` (astral-sh#19364)
  Add shellcheck to pre-commit (astral-sh#19361)
  distinguish references from definitions in `infer_nonlocal`
  [`pycodestyle`] Handle brace escapes for t-strings in logical lines (astral-sh#19358)
  [ty] Combine CallArguments and CallArgumentTypes (astral-sh#19337)
  Move Pylint rendering to `ruff_db` (astral-sh#19340)
  [`pylint`] Extend invalid string character rules to include t-strings (astral-sh#19355)
  Make TC010 docs example more realistic (astral-sh#19356)
  Move RDJSON rendering to `ruff_db` (astral-sh#19293)
  [`flake8-use-pathlib`] Skip single dots for `invalid-pathlib-with-suffix` (`PTH210`) on versions >= 3.14 (astral-sh#19331)
  [`ruff`] Allow `strict` kwarg when checking for `starmap-zip` (`RUF058`) in Python 3.14+ (astral-sh#19333)
  [ty] Reduce false positives for `TypedDict` types (astral-sh#19354)
  [ty] Remove `ConnectionInitializer` (astral-sh#19353)
  [ty] Use `Type::string_literal()` more (astral-sh#19352)
  [ty] Add ecosystem-report workflow (astral-sh#19349)
  [ty] Make use of salsa `Lookup` when interning values (astral-sh#19347)
  ...

# Conflicts:
#	crates/ty_ide/src/goto.rs
#	crates/ty_server/src/server.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal An internal refactor or improvement ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants