Skip to content

[ty] Compare signature parameters before return types - #28383

Draft
charliermarsh wants to merge 1 commit into
mainfrom
charlie/codex-ty-signature-parameter-first
Draft

[ty] Compare signature parameters before return types#28383
charliermarsh wants to merge 1 commit into
mainfrom
charlie/codex-ty-signature-parameter-first

Conversation

@charliermarsh

Copy link
Copy Markdown
Member

Summary

Signature comparisons currently explore return types even when incompatible parameters already rule out a match. For standard parameter lists, we now compare parameters first and skip the return comparison when their constraints cannot be satisfied. This avoids expanding large recursive return types for overloads that cannot match.

We still combine return-type evidence before parameter evidence when selecting constraint solutions. Diagnostic collection and ParamSpec signatures retain the original evaluation order, including binding behavior for incompatible returns.

Against e579b84aba, the existing Pydantic CodSpeed walltime benchmark measured 2.722 s before and 2.628 s after this change alone. This is a 3.5% reduction in elapsed time in this sample. These local measurements use one process pair with six samples per process and two iterations per sample.

@charliermarsh charliermarsh added the ty Multi-file analysis & type inference label Sep 7, 2026
@astral-sh-bot

astral-sh-bot Bot commented Sep 7, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 97.84%. The percentage of expected errors that received a diagnostic held steady at 96.45%. The number of fully passing files held steady at 128/145.

@astral-sh-bot

astral-sh-bot Bot commented Sep 7, 2026

Copy link
Copy Markdown

Memory usage report

Summary

Project Old New Diff Outcome
flake8 38.94MB 38.94MB -0.00% (100.00B) ⬇️
sphinx 167.73MB 167.70MB -0.02% (28.33kB) ⬇️
trio 93.95MB 93.91MB -0.05% (44.32kB) ⬇️
prefect 468.32MB 468.16MB -0.03% (161.66kB) ⬇️

Significant changes

Click to expand detailed breakdown

flake8

Name Old New Diff Outcome
when_constraint_set_assignable_to_owned_impl 87.15kB 87.05kB -0.11% (100.00B) ⬇️

sphinx

Name Old New Diff Outcome
is_redundant_with_impl 794.74kB 784.80kB -1.25% (9.94kB) ⬇️
infer_expression_types_impl 11.39MB 11.38MB -0.08% (9.33kB) ⬇️
CallableType 1.73MB 1.74MB +0.29% (5.08kB)
when_constraint_set_assignable_to_owned_impl 910.76kB 906.61kB -0.46% (4.15kB) ⬇️
union_from_two_elements 76.91kB 73.22kB -4.80% (3.70kB) ⬇️
Type<'db>::class_member_with_policy_inner_ 3.27MB 3.27MB -0.07% (2.45kB) ⬇️
protocol_apply_self_with_receiver::interned_arguments 432.96kB 434.89kB +0.45% (1.93kB)
GenericAlias<'db>::try_mro_ 1.43MB 1.43MB -0.11% (1.60kB) ⬇️
member_lookup_with_policy_inner 3.64MB 3.64MB -0.03% (1.17kB) ⬇️
MemberLookupKey 3.01MB 3.01MB -0.03% (1.02kB) ⬇️
Type<'db>::cached_materialization_::interned_arguments 275.31kB 276.17kB +0.31% (880.00B)
VarianceVariable 75.38kB 74.53kB -1.12% (864.00B) ⬇️
Specialization 1.75MB 1.75MB -0.04% (816.00B) ⬇️
protocol_apply_self_with_receiver 169.18kB 169.92kB +0.44% (760.00B)
TypePair 2.34MB 2.34MB -0.02% (576.00B) ⬇️
... 40 more

trio

Name Old New Diff Outcome
GenericAlias<'db>::try_mro_ 764.43kB 755.83kB -1.13% (8.60kB) ⬇️
Specialization 1.16MB 1.15MB -0.38% (4.52kB) ⬇️
TupleType<'db>::to_class_type_ 43.31kB 39.02kB -9.92% (4.30kB) ⬇️
TypeVarSetInner 264.27kB 260.80kB -1.31% (3.47kB) ⬇️
GenericAlias 410.91kB 408.02kB -0.70% (2.88kB) ⬇️
VarianceVariable 90.47kB 88.03kB -2.69% (2.44kB) ⬇️
TypePair 1.06MB 1.06MB -0.14% (1.50kB) ⬇️
VarianceVariable<'db>::effective_variance_ 42.36kB 40.98kB -3.26% (1.38kB) ⬇️
VarianceVariable<'db>::equation_ 49.06kB 47.73kB -2.71% (1.33kB) ⬇️
GenericAlias<'db>::variance_equation_::interned_arguments 32.91kB 31.62kB -3.92% (1.29kB) ⬇️
merge_inner::interned_arguments 8.02kB 6.96kB -13.16% (1.05kB) ⬇️
is_redundant_with_impl 370.40kB 369.38kB -0.28% (1.02kB) ⬇️
StaticClassLiteral<'db>::variance_equation_::interned_arguments 49.59kB 48.64kB -1.91% (968.00B) ⬇️
MemberLookupKey 1.14MB 1.14MB -0.07% (832.00B) ⬇️
Type<'db>::class_member_with_policy_inner_ 1.28MB 1.28MB -0.06% (808.00B) ⬇️
... 35 more

prefect

Name Old New Diff Outcome
is_redundant_with_impl 3.45MB 3.29MB -4.50% (158.89kB) ⬇️
GenericAlias<'db>::try_mro_ 4.08MB 4.08MB -0.08% (3.27kB) ⬇️
when_constraint_set_assignable_to_owned_impl 3.68MB 3.67MB -0.08% (3.01kB) ⬇️
CallableType 8.77MB 8.77MB +0.02% (1.59kB)
ProtocolInterface 799.27kB 800.41kB +0.14% (1.13kB)
Type<'db>::cached_materialization_ 960.69kB 959.80kB -0.09% (904.00B) ⬇️
Specialization 5.17MB 5.17MB -0.02% (848.00B) ⬇️
Type<'db>::apply_specialization_inner_::interned_arguments 3.96MB 3.96MB +0.01% (560.00B)
FunctionType 6.88MB 6.88MB +0.01% (552.00B)
GenericAlias 1.89MB 1.89MB -0.02% (432.00B) ⬇️
Type<'db>::apply_specialization_inner_ 2.83MB 2.83MB +0.01% (344.00B)
protocol_apply_self_with_receiver::interned_arguments 688.09kB 688.39kB +0.04% (312.00B)
cached_protocol_interface 218.72kB 218.95kB +0.10% (232.00B)
is_equivalent_to_object_inner::interned_arguments 153.19kB 153.38kB +0.12% (192.00B)
is_equivalent_to_object_inner 157.21kB 157.40kB +0.12% (192.00B)
... 16 more

@astral-sh-bot

astral-sh-bot Bot commented Sep 7, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-argument-type 0 0 2
invalid-return-type 0 0 2
Total 0 0 4

Raw diff:

Expression (https://github.com/cognitedata/Expression)
- docs/guides/pipelines.py:50:21 error[invalid-argument-type] Argument is incorrect: Expected `Unknown & _A'return@curry_flip`, found `list[dict[str, str | bool]]`
+ docs/guides/pipelines.py:50:21 error[invalid-argument-type] Argument is incorrect: Expected `_A'return@curry_flip & Unknown`, found `list[dict[str, str | bool]]`
- docs/tutorial/introduction.py:58:21 error[invalid-argument-type] Argument is incorrect: Expected `Unknown & _A'return@curry_flip`, found `list[dict[str, str | int]]`
+ docs/tutorial/introduction.py:58:21 error[invalid-argument-type] Argument is incorrect: Expected `_A'return@curry_flip & Unknown`, found `list[dict[str, str | int]]`

static-frame (https://github.com/static-frame/static-frame)
- static_frame/core/index.py:1297:16 error[invalid-return-type] Return type does not match returned value: expected `Iterator[Hashable | complex | integer[Any] | ... omitted 8 union elements]`, found `reversed[ndarray[tuple[Any, ...], Any] | Any]`
+ static_frame/core/index.py:1297:16 error[invalid-return-type] Return type does not match returned value: expected `Iterator[Hashable | complex | integer[Any] | ... omitted 8 union elements]`, found `reversed[Any | ndarray[tuple[Any, ...], Any]]`
- static_frame/core/series_mapping.py:60:16 error[invalid-return-type] Return type does not match returned value: expected `Iterator[TVValues@SeriesMappingValuesView]`, found `reversed[ndarray[tuple[Any, ...], Any] | Any]`
+ static_frame/core/series_mapping.py:60:16 error[invalid-return-type] Return type does not match returned value: expected `Iterator[TVValues@SeriesMappingValuesView]`, found `reversed[Any | ndarray[tuple[Any, ...], Any]]`

Full report with detailed diff (timing results)

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.

1 participant