Skip to content

[ty] Compare bound-method receivers before signatures - #28384

Draft
charliermarsh wants to merge 1 commit into
mainfrom
charlie/codex-ty-bound-method-receiver-first
Draft

[ty] Compare bound-method receivers before signatures#28384
charliermarsh wants to merge 1 commit into
mainfrom
charlie/codex-ty-bound-method-receiver-first

Conversation

@charliermarsh

Copy link
Copy Markdown
Member

Summary

Bound methods with incompatible captured receivers currently compare their function signatures first, which can expand recursive Self bounds unnecessarily. We now check the captured receivers first and reject the relation immediately when that comparison produces an unconditional failure.

Function evidence still precedes receiver evidence in the resulting constraints. Diagnostic collection retains the original evaluation order so signature mismatches keep their existing error context.

Against e579b84aba, the existing Pydantic CodSpeed walltime benchmark measured 2.704 s before and 2.615 s after this change alone. This is a 3.3% 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% (676.00B) ⬇️
trio 93.95MB 93.94MB -0.01% (8.95kB) ⬇️
sphinx 167.73MB 167.63MB -0.06% (100.17kB) ⬇️
prefect 468.32MB 467.27MB -0.22% (1.05MB) ⬇️

Significant changes

Click to expand detailed breakdown

flake8

Name Old New Diff Outcome
TypeVarSetInner 51.84kB 51.45kB -0.76% (404.00B) ⬇️
merge_inner::interned_arguments 360.00B 216.00B -40.00% (144.00B) ⬇️
merge_inner 240.00B 144.00B -40.00% (96.00B) ⬇️
is_redundant_with_impl 84.30kB 84.27kB -0.04% (32.00B) ⬇️

trio

Name Old New Diff Outcome
TypeVarSetInner 264.27kB 260.63kB -1.38% (3.64kB) ⬇️
GenericContext 570.40kB 568.27kB -0.37% (2.13kB) ⬇️
BoundTypeVarInstance 331.38kB 330.17kB -0.36% (1.20kB) ⬇️
merge_inner::interned_arguments 8.02kB 7.38kB -7.89% (648.00B) ⬇️
merge_inner 5.34kB 4.92kB -7.89% (432.00B) ⬇️
infer_definition_types 4.66MB 4.66MB -0.01% (320.00B) ⬇️
bound_typevar_default_type 14.30kB 14.02kB -1.97% (288.00B) ⬇️
loop_header_reachability 99.73kB 99.58kB -0.16% (160.00B) ⬇️
infer_expression_types_impl 6.11MB 6.11MB -0.00% (160.00B) ⬇️
is_redundant_with_impl 370.40kB 370.30kB -0.03% (104.00B) ⬇️
infer_scope_types_impl 2.82MB 2.82MB +0.00% (56.00B)
member_lookup_with_policy_inner 1.24MB 1.24MB +0.00% (40.00B)

sphinx

Name Old New Diff Outcome
TypeVarSetInner 452.88kB 410.14kB -9.44% (42.74kB) ⬇️
GenericContext 902.71kB 883.37kB -2.14% (19.34kB) ⬇️
BoundTypeVarInstance 802.57kB 791.57kB -1.37% (11.00kB) ⬇️
merge_inner::interned_arguments 18.56kB 9.28kB -50.00% (9.28kB) ⬇️
merge_inner 12.38kB 6.19kB -50.00% (6.19kB) ⬇️
bound_typevar_default_type 13.72kB 10.72kB -21.87% (3.00kB) ⬇️
is_redundant_with_impl 794.74kB 792.27kB -0.31% (2.48kB) ⬇️
TypePair 2.34MB 2.34MB -0.04% (960.00B) ⬇️
infer_expression_types_impl 11.39MB 11.39MB -0.01% (904.00B) ⬇️
Specialization 1.75MB 1.75MB -0.04% (752.00B) ⬇️
all_narrowing_constraints_for_expression 1.64MB 1.64MB -0.04% (640.00B) ⬇️
UnionType 627.70kB 627.16kB -0.09% (560.00B) ⬇️
infer_scope_types_impl 6.12MB 6.12MB -0.01% (560.00B) ⬇️
IntersectionType 631.73kB 631.41kB -0.05% (336.00B) ⬇️
analyze_condition 416.20kB 415.94kB -0.06% (264.00B) ⬇️
... 8 more

prefect

Name Old New Diff Outcome
is_redundant_with_impl 3.45MB 3.10MB -10.07% (355.47kB) ⬇️
infer_definition_types 36.69MB 36.39MB -0.83% (310.45kB) ⬇️
member_lookup_with_policy_inner 9.27MB 9.12MB -1.66% (157.76kB) ⬇️
TypeVarSetInner 1.13MB 1.05MB -6.83% (78.74kB) ⬇️
GenericContext 2.18MB 2.15MB -1.52% (33.96kB) ⬇️
BoundTypeVarInstance 1.62MB 1.59MB -1.46% (24.15kB) ⬇️
TypePair 8.19MB 8.17MB -0.25% (20.62kB) ⬇️
Specialization 5.17MB 5.15MB -0.34% (17.95kB) ⬇️
GenericAlias<'db>::try_mro_ 4.08MB 4.07MB -0.34% (14.16kB) ⬇️
merge_inner::interned_arguments 41.06kB 27.35kB -33.39% (13.71kB) ⬇️
IntersectionType 1.63MB 1.62MB -0.72% (11.98kB) ⬇️
merge_inner 27.38kB 18.23kB -33.39% (9.14kB) ⬇️
GenericAlias 1.89MB 1.88MB -0.31% (6.05kB) ⬇️
bound_typevar_default_type 47.43kB 42.41kB -10.57% (5.02kB) ⬇️
UnionType 1.37MB 1.36MB -0.34% (4.72kB) ⬇️
... 26 more

@astral-sh-bot

astral-sh-bot Bot commented Sep 7, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Flaky changes detected. This PR summary excludes flaky changes; see the HTML report for details.

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