Skip to content

Conversation

dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Sep 4, 2025

Summary

closes: astral-sh/ty#247

This PR adds support for variadic arguments to overload call evaluation.

This basically boils down to making sure that the overloads are not filtered out incorrectly during the step 5 in the overload call evaluation algorithm. For context, the step 5 tries to filter out the remaining overloads after finding an overload where the materialization of argument types are assignable to the parameter types.

The issue with the previous implementation was that it wouldn't unpack the variadic argument and wouldn't consider the many-to-one (multiple arguments mapping to a single variadic parameter) correctly. This PR fixes that.

Test Plan

Update existing test cases and resolve the TODOs.

@dhruvmanila dhruvmanila added the ty Multi-file analysis & type inference label Sep 4, 2025
Copy link
Contributor

github-actions bot commented Sep 4, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

Copy link
Contributor

github-actions bot commented Sep 4, 2025

mypy_primer results

Changes were detected when running on open source projects
attrs (https://github.com/python-attrs/attrs)
- tests/test_dunders.py:677:15: error[too-many-positional-arguments] Too many positional arguments to bound method `__init__`: expected 1, got 2
+ tests/test_dunders.py:677:15: error[too-many-positional-arguments] Too many positional arguments: expected 0, got 1
- tests/test_make.py:2169:15: error[too-many-positional-arguments] Too many positional arguments to bound method `__init__`: expected 1, got 2
+ tests/test_make.py:2169:15: error[too-many-positional-arguments] Too many positional arguments: expected 0, got 1
- tests/test_make.py:2191:22: error[too-many-positional-arguments] Too many positional arguments to bound method `__init__`: expected 1, got 2
+ tests/test_make.py:2191:22: error[too-many-positional-arguments] Too many positional arguments: expected 0, got 1
- tests/test_make.py:2192:30: error[too-many-positional-arguments] Too many positional arguments to bound method `__init__`: expected 1, got 2
+ tests/test_make.py:2192:30: error[too-many-positional-arguments] Too many positional arguments: expected 0, got 1

porcupine (https://github.com/Akuli/porcupine)
- porcupine/plugins/git_right_click.py:56:22: error[unresolved-attribute] Type `str` has no attribute `decode`
- porcupine/plugins/git_right_click.py:57:24: error[unresolved-attribute] Type `str` has no attribute `decode`
- Found 26 diagnostics
+ Found 24 diagnostics

pwndbg (https://github.com/pwndbg/pwndbg)
+ pwndbg/dbg/gdb/__init__.py:1750:9: error[invalid-assignment] Object of type `str` is not assignable to `Literal["att", "intel"]`
- Found 2571 diagnostics
+ Found 2572 diagnostics

scikit-build-core (https://github.com/scikit-build/scikit-build-core)
+ src/scikit_build_core/build/_wheelfile.py:51:22: error[no-matching-overload] No overload of function `field` matches arguments
- Found 52 diagnostics
+ Found 53 diagnostics

prefect (https://github.com/PrefectHQ/prefect)
+ src/integrations/prefect-kubernetes/prefect_kubernetes/worker.py:627:5: error[invalid-assignment] Object of type `Literal[KubernetesImagePullPolicy.IF_NOT_PRESENT]` is not assignable to `Literal["IfNotPresent", "Always", "Never"]`
+ src/integrations/prefect-snowflake/prefect_snowflake/experimental/workers/spcs.py:109:5: error[invalid-assignment] Object of type `None` is not assignable to `str`
+ src/integrations/prefect-snowflake/prefect_snowflake/experimental/workers/spcs.py:141:5: error[invalid-assignment] Object of type `None` is not assignable to `str`
+ src/integrations/prefect-snowflake/prefect_snowflake/experimental/workers/spcs.py:156:5: error[invalid-assignment] Object of type `None` is not assignable to `str`
+ src/integrations/prefect-snowflake/prefect_snowflake/experimental/workers/spcs.py:256:5: error[invalid-assignment] Object of type `None` is not assignable to `str`
+ src/integrations/prefect-snowflake/prefect_snowflake/experimental/workers/spcs.py:287:5: error[invalid-assignment] Object of type `None` is not assignable to `str`
+ src/integrations/prefect-snowflake/prefect_snowflake/experimental/workers/spcs.py:302:5: error[invalid-assignment] Object of type `None` is not assignable to `str`
- Found 3180 diagnostics
+ Found 3187 diagnostics

core (https://github.com/home-assistant/core)
- homeassistant/components/sonos/diagnostics.py:129:20: error[invalid-return-type] Return type does not match returned value: expected `int | float | str | dict[str, Any]`, found `MappingProxyType[str, Any]`
- Found 13733 diagnostics
+ Found 13732 diagnostics
No memory usage changes detected ✅

@dhruvmanila dhruvmanila force-pushed the dhruv/retry-parameter-matching branch from 63fe1a7 to 4184ce9 Compare September 8, 2025 06:24
Base automatically changed from dhruv/retry-parameter-matching to main September 12, 2025 08:40
@dhruvmanila dhruvmanila changed the title [ty] Skip overload filtering if there are no participating parameters [ty] Support single-starred argument for overload call Sep 19, 2025
Copy link

codspeed-hq bot commented Sep 29, 2025

CodSpeed WallTime Performance Report

Merging #20223 will not alter performance

Comparing dhruv/skip-filtering (58d4d9f) with main (8664842)

Summary

✅ 8 untouched

Copy link

codspeed-hq bot commented Sep 29, 2025

CodSpeed Instrumentation Performance Report

Merging #20223 will not alter performance

Comparing dhruv/skip-filtering (58d4d9f) with main (8664842)

Summary

✅ 13 untouched
⏩ 30 skipped1

Footnotes

  1. 30 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@dhruvmanila
Copy link
Member Author

dhruvmanila commented Sep 29, 2025

I plan on looking at the performance regression tomorrow morning but otherwise I think this is ready to get some initial feedback.

It seems like it was just noise.

@dhruvmanila dhruvmanila marked this pull request as ready for review September 29, 2025 17:15
Copy link
Member

@dcreager dcreager 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!

@dcreager dcreager merged commit 4e94b22 into main Oct 2, 2025
39 checks passed
@dcreager dcreager deleted the dhruv/skip-filtering branch October 2, 2025 14:41
dcreager added a commit that referenced this pull request Oct 3, 2025
* origin/main:
  [`flake8-bugbear`] Include certain guaranteed-mutable expressions: tuples, generators, and assignment expressions (`B006`) (#20024)
  [`flake8-comprehensions`] Clarify fix safety documentation (`C413`) (#20640)
  [ty] improve base conda distinction from child conda (#20675)
  [`ruff`] Extend FA102 with listed PEP 585-compatible APIs (#20659)
  [`ruff`] Handle argfile expansion errors gracefully (#20691)
  [`flynt`] Fix f-string quoting for mixed quote joiners (`FLY002`) (#20662)
  [ty] Fix file root matching for `/`
  [ruff,ty] Enable tracing's `log` feature
  [`flake8-annotations`] Fix return type annotations to handle shadowed builtin symbols (`ANN201`, `ANN202`, `ANN204`, `ANN205`, `ANN206`) (#20612)
  Bump 0.13.3 (#20685)
  Update benchmarking CI for cargo-codspeed v4 (#20686)
  [ty] Support single-starred argument for overload call (#20223)
  [ty] `~T` should never be assignable to `T` (#20606)
  [`pylint`] Clarify fix safety to include left-hand hashability (`PLR6201`) (#20518)
  [ty] No union with `Unknown` for module-global symbols (#20664)
  [`ty`] Reject renaming files to start with slash in Playground (#20666)
  [ty] Enums: allow multiple aliases to point to the same member (#20669)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support starred/splatted/unpacked arguments in function calls

2 participants