Skip to content

[ty] Split equality from other comparison inference#26370

Open
charliermarsh wants to merge 3 commits into
mainfrom
charlie/split-equality-comparison-inference
Open

[ty] Split equality from other comparison inference#26370
charliermarsh wants to merge 3 commits into
mainfrom
charlie/split-equality-comparison-inference

Conversation

@charliermarsh

Copy link
Copy Markdown
Member

Summary

#26337 routes definite == and != results through the shared equality evaluator before falling back to normal expression inference. When that evaluator returns ambiguous truthiness, however, we still run the full comparison dispatcher, repeating literal, tuple, and constraint-set work just to distinguish a builtin bool result from an arbitrary custom comparison return type.

This splits the top-level dispatch between equality and the other comparison operators. Equality evaluation now distinguishes definite truthiness, ambiguous builtin bool, and comparisons whose result type still needs to be inferred. Known builtin comparisons can stop after the shared evaluator, while custom comparisons continue through structural dispatch and the existing dunder fallback. The remaining literal dispatch uses a narrower non-equality operator enum, so it no longer duplicates the == and != cases.

To make the shared path complete, this also moves constraint-set equality and builtin tuple equality into the equality evaluator. Fixed-length tuples compare their elements using equality semantics even for an outer !=, while uncertain element results still fall back to expression inference so custom return types and bool-conversion diagnostics are preserved. Regression coverage verifies that equality and inequality over union arms retain each custom dunder return type.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Jun 25, 2026
@charliermarsh charliermarsh force-pushed the charlie/split-equality-comparison-inference branch from 11023c6 to 8c8c117 Compare June 25, 2026 16:26
@astral-sh-bot

astral-sh-bot Bot commented Jun 25, 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 94.47%. The percentage of expected errors that received a diagnostic held steady at 89.19%. The number of fully passing files held steady at 95/134.

@astral-sh-bot

astral-sh-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

Memory usage report

Summary

Project Old New Diff Outcome
sphinx 166.58MB 166.59MB +0.00% (6.23kB)
flake8 28.94MB 28.94MB +0.00% (312.00B)
trio 70.26MB 70.26MB -0.01% (4.64kB) ⬇️
prefect 448.12MB 448.10MB -0.00% (13.75kB) ⬇️

Significant changes

Click to expand detailed breakdown

sphinx

Name Old New Diff Outcome
IntersectionType 534.04kB 539.61kB +1.04% (5.57kB)
all_narrowing_constraints_for_expression 1.93MB 1.93MB +0.20% (3.98kB)
infer_expression_types_impl 14.77MB 14.77MB -0.01% (1.09kB)
Type<'db>::class_member_with_policy_ 3.60MB 3.60MB -0.02% (832.00B)
member_lookup_with_policy_inner::interned_arguments 2.70MB 2.70MB -0.02% (600.00B)
place_table 183.05kB 183.56kB +0.28% (528.00B)
Type<'db>::class_member_with_policy_::interned_arguments 2.36MB 2.36MB -0.02% (520.00B)
member_lookup_with_policy_inner 4.28MB 4.28MB -0.01% (416.00B)
BoundMethodType 771.17kB 770.78kB -0.05% (400.00B)
infer_scope_types_impl 8.10MB 8.10MB -0.00% (48.00B)

flake8

Name Old New Diff Outcome
IntersectionType 53.87kB 54.05kB +0.33% (184.00B)
all_narrowing_constraints_for_expression 71.97kB 72.09kB +0.17% (128.00B)

trio

Name Old New Diff Outcome
UnionType 144.56kB 143.45kB -0.77% (1.11kB) ⬇️
Type<'db>::class_member_with_policy_ 888.81kB 887.97kB -0.09% (864.00B) ⬇️
member_lookup_with_policy_inner::interned_arguments 765.70kB 765.12kB -0.08% (600.00B) ⬇️
Type<'db>::class_member_with_policy_::interned_arguments 626.54kB 626.03kB -0.08% (520.00B) ⬇️
infer_expression_types_impl 4.37MB 4.37MB -0.01% (488.00B) ⬇️
member_lookup_with_policy_inner 1.03MB 1.02MB -0.04% (416.00B) ⬇️
BoundMethodType 180.47kB 180.08kB -0.22% (400.00B) ⬇️
infer_definition_types 3.96MB 3.96MB -0.01% (224.00B) ⬇️
all_narrowing_constraints_for_expression 457.70kB 457.79kB +0.02% (88.00B) ⬇️
infer_deferred_types 1.20MB 1.20MB -0.01% (64.00B) ⬇️
function_known_decorators 236.04kB 235.98kB -0.03% (64.00B) ⬇️
loop_header_reachability 71.16kB 71.10kB -0.09% (64.00B) ⬇️

prefect

Name Old New Diff Outcome
Type<'db>::class_member_with_policy_ 7.91MB 7.90MB -0.05% (4.30kB) ⬇️
infer_expression_types_impl 37.77MB 37.77MB -0.01% (4.09kB) ⬇️
all_narrowing_constraints_for_expression 5.19MB 5.19MB +0.06% (3.05kB) ⬇️
member_lookup_with_policy_inner::interned_arguments 6.73MB 6.73MB -0.04% (3.05kB) ⬇️
Type<'db>::class_member_with_policy_::interned_arguments 5.73MB 5.72MB -0.05% (2.64kB) ⬇️
member_lookup_with_policy_inner 10.21MB 10.21MB -0.02% (2.53kB) ⬇️
IntersectionType 984.91kB 987.43kB +0.26% (2.52kB) ⬇️
BoundMethodType 1.69MB 1.69MB -0.12% (2.03kB) ⬇️
place_table 703.83kB 704.67kB +0.12% (864.00B) ⬇️
infer_definition_types 49.92MB 49.92MB -0.00% (664.00B) ⬇️
UnionType 1.07MB 1.07MB -0.05% (512.00B) ⬇️
place_by_id 4.78MB 4.78MB -0.00% (104.00B) ⬇️
analyze_non_terminal_call 1.77MB 1.77MB -0.01% (104.00B) ⬇️
infer_scope_types_impl 30.11MB 30.11MB -0.00% (80.00B) ⬇️
loop_header_reachability 251.37kB 251.32kB -0.02% (56.00B) ⬇️
... 3 more

@astral-sh-bot

astral-sh-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@charliermarsh charliermarsh force-pushed the charlie/split-equality-comparison-inference branch 2 times, most recently from ddfb082 to c072fb1 Compare June 25, 2026 16:39
@charliermarsh charliermarsh force-pushed the charlie/split-equality-comparison-inference branch from c072fb1 to 60d8110 Compare June 25, 2026 17:17
@charliermarsh charliermarsh marked this pull request as ready for review June 25, 2026 17:18
@charliermarsh charliermarsh requested a review from a team as a code owner June 25, 2026 17:18
@astral-sh-bot astral-sh-bot Bot requested a review from dhruvmanila June 25, 2026 17:18
@charliermarsh charliermarsh added the internal An internal refactor or improvement label Jun 25, 2026
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.

1 participant