[ty] Relax union variadic guard to check only parameters beyond minimum length#23298
[ty] Relax union variadic guard to check only parameters beyond minimum length#23298
Conversation
0119403 to
0575be1
Compare
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 86.46%. The percentage of expected errors that received a diagnostic held steady at 80.68%. The number of fully passing files held steady at 67/132. |
|
Memory usage reportMemory usage unchanged ✅ |
23e6f38 to
f1c1699
Compare
543b269 to
188ce13
Compare
0575be1 to
153dfb6
Compare
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
0 | 27 | 2 |
missing-argument |
23 | 0 | 0 |
no-matching-overload |
2 | 0 | 0 |
too-many-positional-arguments |
1 | 0 | 0 |
unused-ignore-comment |
1 | 0 | 0 |
unused-type-ignore-comment |
1 | 0 | 0 |
| Total | 28 | 27 | 2 |
Raw diff (57 changes)
aiortc (https://github.com/aiortc/aiortc)
- src/aiortc/rtcrtpreceiver.py:476:43 error[invalid-argument-type] Argument to function `pack_remb_fci` is incorrect: Expected `int`, found `Unknown | int | list[int]`
- src/aiortc/rtcrtpreceiver.py:476:43 error[invalid-argument-type] Argument to function `pack_remb_fci` is incorrect: Expected `list[int]`, found `Unknown | int | list[int]`
comtypes (https://github.com/enthought/comtypes)
+ comtypes/_memberspec.py:73:61 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
core (https://github.com/home-assistant/core)
+ homeassistant/components/govee_light_local/light.py:226:27 error[missing-argument] No arguments provided for required parameters `green`, `blue` of bound method `set_rgb_color`
+ homeassistant/components/govee_light_local/light.py:228:74 error[too-many-positional-arguments] Too many positional arguments to bound method `set_temperature`: expected 3, got 4
dedupe (https://github.com/dedupeio/dedupe)
- dedupe/core.py:196:41 error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[Unknown]`, found `int | str`
+ dedupe/core.py:196:37 error[no-matching-overload] No overload of function `__new__` matches arguments
pandera (https://github.com/pandera-dev/pandera)
- pandera/backends/ibis/container.py:94:29 error[invalid-argument-type] Argument to bound method `run_schema_component_checks` is incorrect: Expected `Iterable[Unknown]`, found `Unknown | DataFrameSchema | ColumnInfo | bool`
- pandera/backends/ibis/container.py:94:29 error[invalid-argument-type] Argument to bound method `run_schema_component_checks` is incorrect: Expected `bool`, found `Unknown | DataFrameSchema | ColumnInfo | bool`
+ pandera/backends/ibis/container.py:94:23 error[missing-argument] No arguments provided for required parameters `schema_components`, `lazy` of bound method `run_schema_component_checks`
+ pandera/backends/pandas/container.py:182:23 error[missing-argument] No arguments provided for required parameters `schema_components`, `lazy` of bound method `run_schema_component_checks`
- pandera/backends/polars/container.py:118:29 error[invalid-argument-type] Argument to bound method `run_schema_component_checks` is incorrect: Expected `bool`, found `Unknown | DataFrameSchema | bool`
- pandera/backends/polars/container.py:118:29 error[invalid-argument-type] Argument to bound method `run_schema_component_checks` is incorrect: Expected `list[Unknown]`, found `Unknown | DataFrameSchema | bool`
+ pandera/backends/polars/container.py:118:23 error[missing-argument] No arguments provided for required parameters `schema_components`, `lazy` of bound method `run_schema_component_checks`
- pandera/backends/pyspark/container.py:118:29 error[invalid-argument-type] Argument to bound method `run_schema_component_checks` is incorrect: Expected `bool`, found `Unknown | ColumnInfo | bool`
- pandera/backends/pyspark/container.py:118:29 error[invalid-argument-type] Argument to bound method `run_schema_component_checks` is incorrect: Expected `list[Unknown]`, found `Unknown | ColumnInfo | bool`
+ pandera/backends/pyspark/container.py:118:23 error[missing-argument] No arguments provided for required parameters `schema_components`, `lazy` of bound method `run_schema_component_checks`
pip (https://github.com/pypa/pip)
- src/pip/_internal/index/package_finder.py:740:32 error[invalid-argument-type] Argument to function `build_netloc` is incorrect: Expected `int | None`, found `Unknown | str | int | None`
- src/pip/_internal/index/package_finder.py:740:32 error[invalid-argument-type] Argument to function `build_netloc` is incorrect: Expected `str`, found `Unknown | str | int | None`
prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/server/orchestration/rules.py:651:46 error[invalid-argument-type] Argument to bound method `before_transition` is incorrect: Expected `OrchestrationContext[T@BaseOrchestrationRule, RP@BaseOrchestrationRule]`, found `Unknown | State | None | OrchestrationContext[T@BaseOrchestrationRule, RP@BaseOrchestrationRule]`
- src/prefect/server/orchestration/rules.py:651:46 error[invalid-argument-type] Argument to bound method `before_transition` is incorrect: Expected `State | None`, found `Unknown | State | None | OrchestrationContext[T@BaseOrchestrationRule, RP@BaseOrchestrationRule]`
- src/prefect/server/orchestration/rules.py:691:32 error[invalid-argument-type] Argument to bound method `cleanup` is incorrect: Expected `OrchestrationContext[T@BaseOrchestrationRule, RP@BaseOrchestrationRule]`, found `Unknown | State | None | OrchestrationContext[T@BaseOrchestrationRule, RP@BaseOrchestrationRule]`
- src/prefect/server/orchestration/rules.py:691:32 error[invalid-argument-type] Argument to bound method `cleanup` is incorrect: Expected `State | None`, found `Unknown | State | None | OrchestrationContext[T@BaseOrchestrationRule, RP@BaseOrchestrationRule]`
- src/prefect/server/orchestration/rules.py:693:41 error[invalid-argument-type] Argument to bound method `after_transition` is incorrect: Expected `OrchestrationContext[T@BaseOrchestrationRule, RP@BaseOrchestrationRule]`, found `Unknown | State | None | OrchestrationContext[T@BaseOrchestrationRule, RP@BaseOrchestrationRule]`
- src/prefect/server/orchestration/rules.py:693:41 error[invalid-argument-type] Argument to bound method `after_transition` is incorrect: Expected `State | None`, found `Unknown | State | None | OrchestrationContext[T@BaseOrchestrationRule, RP@BaseOrchestrationRule]`
pylint (https://github.com/pycqa/pylint)
- pylint/checkers/base/name_checker/checker.py:370:59 error[invalid-argument-type] Argument to bound method `_raise_name_warning` is incorrect: Expected `Confidence`, found `Unknown | str | Confidence`
- pylint/checkers/base/name_checker/checker.py:370:59 error[invalid-argument-type] Argument to bound method `_raise_name_warning` is incorrect: Expected `str`, found `Unknown | str | Confidence`
- pylint/checkers/base/name_checker/checker.py:370:59 error[invalid-argument-type] Argument to bound method `_raise_name_warning` is incorrect: Expected `str`, found `Unknown | str | Confidence`
- pylint/checkers/base/name_checker/checker.py:370:59 error[invalid-argument-type] Argument to bound method `_raise_name_warning` is incorrect: Expected `str`, found `Unknown | str | Confidence`
pytest (https://github.com/pytest-dev/pytest)
- src/_pytest/terminal.py:665:51 error[invalid-argument-type] Argument to bound method `_locationline` is incorrect: Expected `int | None`, found `str | int | None`
- src/_pytest/terminal.py:665:51 error[invalid-argument-type] Argument to bound method `_locationline` is incorrect: Expected `str`, found `str | int | None`
- src/_pytest/terminal.py:665:51 error[invalid-argument-type] Argument to bound method `_locationline` is incorrect: Expected `str`, found `str | int | None`
pytest-robotframework (https://github.com/detachhead/pytest-robotframework)
+ tests/conftest.py:299:18 error[no-matching-overload] No overload of bound method `run_pytest` matches arguments
+ tests/conftest.py:299:132 warning[unused-ignore-comment] Unused `ty: ignore` directive
scipy (https://github.com/scipy/scipy)
+ scipy/signal/tests/test_filter_design.py:4362:16 error[missing-argument] No argument provided for required parameter `Wn`
+ scipy/signal/tests/test_filter_design.py:4362:16 error[missing-argument] No argument provided for required parameter `Wn`
+ scipy/signal/tests/test_filter_design.py:4362:16 error[missing-argument] No arguments provided for required parameters `rs`, `Wn`
+ scipy/signal/tests/test_filter_design.py:4363:15 error[missing-argument] No argument provided for required parameter `Wn`
+ scipy/signal/tests/test_filter_design.py:4363:15 error[missing-argument] No argument provided for required parameter `Wn`
+ scipy/signal/tests/test_filter_design.py:4363:15 error[missing-argument] No arguments provided for required parameters `rs`, `Wn`
+ scipy/signal/tests/test_filter_design.py:4366:15 error[missing-argument] No argument provided for required parameter `Wn`
+ scipy/signal/tests/test_filter_design.py:4366:15 error[missing-argument] No argument provided for required parameter `Wn`
+ scipy/signal/tests/test_filter_design.py:4366:15 error[missing-argument] No arguments provided for required parameters `rs`, `Wn`
+ scipy/signal/tests/test_filter_design.py:4367:15 error[missing-argument] No argument provided for required parameter `Wn`
+ scipy/signal/tests/test_filter_design.py:4367:15 error[missing-argument] No argument provided for required parameter `Wn`
+ scipy/signal/tests/test_filter_design.py:4367:15 error[missing-argument] No arguments provided for required parameters `rs`, `Wn`
+ scipy/signal/tests/test_filter_design.py:4370:15 error[missing-argument] No argument provided for required parameter `Wn`
+ scipy/signal/tests/test_filter_design.py:4370:15 error[missing-argument] No argument provided for required parameter `Wn`
+ scipy/signal/tests/test_filter_design.py:4370:15 error[missing-argument] No arguments provided for required parameters `rs`, `Wn`
+ scipy/signal/tests/test_filter_design.py:4371:15 error[missing-argument] No argument provided for required parameter `Wn`
+ scipy/signal/tests/test_filter_design.py:4371:15 error[missing-argument] No argument provided for required parameter `Wn`
+ scipy/signal/tests/test_filter_design.py:4371:15 error[missing-argument] No arguments provided for required parameters `rs`, `Wn`
tornado (https://github.com/tornadoweb/tornado)
- tornado/routing.py:349:55 error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `dict[str, Any] | None`, found `@Todo | dict[str, Any] | str`
- tornado/routing.py:349:55 error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `str | None`, found `@Todo | dict[str, Any] | str`
werkzeug (https://github.com/pallets/werkzeug)
- src/werkzeug/test.py:418:38 error[invalid-argument-type] Argument to bound method `add_file` is incorrect: Expected `str | None`, found `bytes | IO[bytes] | str`
+ src/werkzeug/test.py:418:38 error[invalid-argument-type] Argument to bound method `add_file` is incorrect: Expected `str | None`, found `bytes | str`
- src/werkzeug/test.py:418:38 error[invalid-argument-type] Argument to bound method `add_file` is incorrect: Expected `str | None`, found `bytes | IO[bytes] | str`
+ src/werkzeug/test.py:418:38 error[invalid-argument-type] Argument to bound method `add_file` is incorrect: Expected `str | PathLike[str] | IO[bytes] | FileStorage`, found `bytes | IO[bytes]`
- src/werkzeug/test.py:418:38 error[invalid-argument-type] Argument to bound method `add_file` is incorrect: Expected `str | PathLike[str] | IO[bytes] | FileStorage`, found `bytes | IO[bytes] | str`|
Not good yet, don't merge -- found some issues locally and fixing them up. |
|
Ok, so I found that we were being too lax in our treatment of unions of tuples here; if a function accepts two arguments, or requires three arguments, either way calling it with an unpacked union of a 2-tuple and 3-tuple should fail due to arity. Fixing this then exposed another issue, which is that when we have an unpacked union argument, we need to ensure that we expand that union before concluding that any overloads can be eliminated by arity checking. There's a fair amount of new changes here, so going to request re-review. |
| target: "ty_python_semantic::types::call::bind", | ||
| matching_overload_index = ?self.matching_overload_index(), | ||
| "after step 4", | ||
| ); |
There was a problem hiding this comment.
Did you intend to keep this and the other trace calls?
There was a problem hiding this comment.
None of them are new, just moved / indented. So yeah, it wasn't my intent to add or remove any tracing.
|
(I can't approve, but feel free to proceed with merge.) |
|
Did some ecosystem analysis here; all the diagnostic changes look reasonable. Some of the added diagnostics are cases where a union of functions is called with an unpacked union of tuples, and in reality there's an invariant where each function is lined up with a different tuple, but that's not a correlation we can see through. It seems like mypy is pretty lax with unpacking unions of tuples, but our results here line up with pyright and pyrefly reasonably well. |
* main: [ty] Relax union variadic guard to check only parameters beyond minimum length (#23298)
Summary
The guard condition for per-element union iteration in match_variadic previously required all remaining positional parameters to be defaulted. This was overly conservative. We only need parameters beyond the shortest union element's length to be defaulted, since those positions are guaranteed to be provided by every union element.
See: https://github.com/astral-sh/ruff/pull/23124/changes#r2806496807.