Skip to content

[ty] Include inherited object members in protocol comparisons - #27548

Draft
AlexWaygood wants to merge 1 commit into
mainfrom
alex/protocol-object-fallback
Draft

[ty] Include inherited object members in protocol comparisons#27548
AlexWaygood wants to merge 1 commit into
mainfrom
alex/protocol-object-fallback

Conversation

@AlexWaygood

Copy link
Copy Markdown
Member

Summary

  • Route protocol-to-protocol comparisons through ordinary member lookup so inherited object methods can satisfy compatible structural requirements.
  • Preserve hashability semantics by requiring protocols to explicitly provide a callable __hash__.
  • Keep recursive protocol comparisons ordered safely and retain distinct diagnostics for read-only protocol members.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Aug 6, 2026
@astral-sh-bot

astral-sh-bot Bot commented Aug 6, 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 96.96%. The percentage of expected errors that received a diagnostic held steady at 92.96%. The number of fully passing files held steady at 106/133.

@astral-sh-bot

astral-sh-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

Memory usage report

Summary

Project Old New Diff Outcome
prefect 667.91MB 668.01MB +0.01% (98.43kB)
sphinx 209.43MB 209.45MB +0.01% (16.66kB)
trio 94.66MB 94.67MB +0.01% (14.18kB)
flake8 40.42MB 40.43MB +0.01% (5.45kB)

Significant changes

Click to expand detailed breakdown

prefect

Name Old New Diff Outcome
protocol_member_names_by_structural_priority 0.00B 36.31kB +36.31kB (new)
inherited_object_protocol_member_count 0.00B 8.65kB +8.65kB (new)
CallableType 11.24MB 11.25MB +0.07% (8.57kB)
Type<'db>::class_member_with_policy_inner_ 12.50MB 12.51MB +0.05% (6.82kB)
MemberLookupKey 9.95MB 9.96MB +0.07% (6.80kB)
member_lookup_with_policy_inner 14.54MB 14.54MB +0.03% (5.00kB)
is_redundant_with_impl 4.07MB 4.08MB +0.11% (4.79kB)
BoundMethodType<'db>::bound_signatures_ 1.79MB 1.80MB +0.15% (2.78kB)
infer_definition_types 60.42MB 60.42MB +0.00% (2.74kB)
infer_expression_types_impl 47.16MB 47.16MB +0.00% (2.41kB)
Type<'db>::cached_materialization_::interned_arguments 1.93MB 1.93MB +0.11% (2.27kB)
Type<'db>::cached_materialization_ 1.42MB 1.43MB +0.13% (1.94kB)
enum_metadata 1.74MB 1.74MB +0.09% (1.59kB)
try_call_dunder_get_inner::interned_arguments 1.62MB 1.62MB +0.07% (1.09kB)
BoundMethodType 3.23MB 3.23MB +0.03% (960.00B)
... 34 more

sphinx

Name Old New Diff Outcome
protocol_member_names_by_structural_priority 0.00B 16.33kB +16.33kB (new)
protocol_apply_self_with_receiver::interned_arguments 502.33kB 498.57kB -0.75% (3.76kB) ⬇️
inherited_object_protocol_member_count 0.00B 2.62kB +2.62kB (new)
is_redundant_with_impl 1.02MB 1.02MB +0.21% (2.18kB)
protocol_apply_self_with_receiver 196.26kB 194.81kB -0.74% (1.45kB) ⬇️
BoundMethodType<'db>::bound_signatures_ 486.72kB 487.83kB +0.23% (1.11kB)
member_lookup_with_policy_inner 5.36MB 5.35MB -0.01% (736.00B) ⬇️
infer_expression_types_impl 16.80MB 16.80MB +0.00% (680.00B)
Type<'db>::class_member_with_policy_inner_ 3.33MB 3.33MB -0.02% (600.00B) ⬇️
infer_scope_types_impl 8.42MB 8.42MB -0.01% (584.00B) ⬇️
MemberLookupKey 3.43MB 3.42MB -0.01% (520.00B) ⬇️
Type<'db>::cached_materialization_::interned_arguments 488.12kB 488.59kB +0.10% (480.00B)
Type<'db>::cached_materialization_ 318.85kB 319.31kB +0.14% (472.00B)
protocol_bind_self::interned_arguments 97.20kB 96.77kB -0.44% (440.00B) ⬇️
infer_definition_types 14.06MB 14.06MB -0.00% (312.00B) ⬇️
... 17 more

trio

Name Old New Diff Outcome
protocol_member_names_by_structural_priority 0.00B 6.05kB +6.05kB (new)
CallableType 1.42MB 1.42MB +0.20% (2.95kB)
inherited_object_protocol_member_count 0.00B 1.04kB +1.04kB (new)
Type<'db>::cached_materialization_::interned_arguments 303.59kB 304.38kB +0.26% (800.00B)
infer_definition_types 4.51MB 4.51MB +0.02% (728.00B)
BoundTypeVarInstance 229.45kB 230.14kB +0.30% (704.00B)
Type<'db>::cached_materialization_ 211.57kB 212.23kB +0.31% (680.00B)
is_redundant_with_impl 326.69kB 327.34kB +0.20% (672.00B)
TypeVarInstance 73.69kB 74.25kB +0.76% (576.00B)
MaterializedProtocolType 12.59kB 12.87kB +2.23% (288.00B)
protocol_apply_self_with_receiver::interned_arguments 138.94kB 138.73kB -0.15% (208.00B) ⬇️
BoundMethodType<'db>::bound_signatures_ 199.51kB 199.66kB +0.07% (152.00B)
when_constraint_set_assignable_to_owned_impl 976.25kB 976.38kB +0.01% (128.00B)
MemberLookupKey 1.15MB 1.15MB -0.01% (104.00B) ⬇️
protocol_apply_self_with_receiver 54.70kB 54.62kB -0.14% (80.00B) ⬇️
... 7 more

flake8

Name Old New Diff Outcome
protocol_member_names_by_structural_priority 0.00B 3.28kB +3.28kB (new)
CallableType 293.68kB 294.23kB +0.19% (568.00B)
inherited_object_protocol_member_count 0.00B 168.00B +168.00B (new)
Type<'db>::class_member_with_policy_inner_ 263.57kB 263.73kB +0.06% (168.00B)
is_redundant_with_impl 82.29kB 82.45kB +0.20% (168.00B)
BoundMethodType<'db>::bound_signatures_ 40.30kB 40.45kB +0.37% (152.00B)
MemberLookupKey 278.54kB 278.64kB +0.04% (104.00B)
TypeVarInstance 22.69kB 22.78kB +0.41% (96.00B)
BoundTypeVarInstance 60.67kB 60.76kB +0.14% (88.00B)
protocol_bind_self::interned_arguments 15.47kB 15.55kB +0.56% (88.00B)
Type<'db>::cached_materialization_::interned_arguments 67.97kB 68.05kB +0.11% (80.00B)
remove_self_inner::interned_arguments 4.99kB 5.06kB +1.41% (72.00B)
MaterializedProtocolType 1.97kB 2.04kB +3.57% (72.00B)
member_lookup_with_policy_inner 324.18kB 324.24kB +0.02% (64.00B)
Type<'db>::cached_materialization_ 42.99kB 43.05kB +0.15% (64.00B)
... 10 more

@astral-sh-bot

astral-sh-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Large timing changes:

Project Old Time New Time Change
DateType 0.05s 0.07s +52%

Full report with detailed diff (timing results)

@codspeed-hq

codspeed-hq Bot commented Aug 6, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 23.22%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 5 regressed benchmarks
✅ 106 untouched benchmarks
⏩ 84 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation ty_micro[many_protocol_members_mismatch] 573.4 ms 1,043.6 ms -45.06%
Simulation DateType 236 ms 405.4 ms -41.79%
Memory DateType 14.8 MB 16 MB -7.46%
WallTime colour_science 36.2 s 38.2 s -5.35%
WallTime static_frame 27.8 s 29.2 s -4.76%

Tip

Investigate this regression with the CodSpeed MCP and your agent.


Comparing alex/protocol-object-fallback (844b2bd) with main (6ea296b)

Open in CodSpeed

Footnotes

  1. 84 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.

@AlexWaygood
AlexWaygood force-pushed the alex/protocol-object-fallback branch 3 times, most recently from 4be5e68 to af58f84 Compare August 6, 2026 15:16
@AlexWaygood
AlexWaygood force-pushed the alex/protocol-object-fallback branch from af58f84 to 844b2bd Compare August 6, 2026 15:48
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