Skip to content

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

Draft
AlexWaygood wants to merge 3 commits into
mainfrom
alex/protocol-object-fallback
Draft

[ty] Include inherited object members in protocol comparisons#27548
AlexWaygood wants to merge 3 commits 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 454.40MB 454.48MB +0.02% (81.47kB)
sphinx 165.24MB 165.25MB +0.01% (16.73kB)
trio 93.36MB 93.37MB +0.01% (14.18kB)
flake8 40.41MB 40.41MB +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 28.26kB +28.26kB (new)
CallableType 7.99MB 8.00MB +0.10% (8.43kB)
inherited_object_protocol_member_count 0.00B 7.83kB +7.83kB (new)
Type<'db>::class_member_with_policy_inner_ 8.68MB 8.69MB +0.05% (4.76kB)
MemberLookupKey 6.81MB 6.82MB +0.07% (4.67kB)
is_redundant_with_impl 3.36MB 3.36MB +0.12% (4.01kB)
member_lookup_with_policy_inner 10.75MB 10.75MB +0.03% (3.35kB)
BoundMethodType<'db>::bound_signatures_ 1.24MB 1.25MB +0.19% (2.42kB)
Type<'db>::cached_materialization_::interned_arguments 1.37MB 1.38MB +0.16% (2.19kB)
infer_definition_types 34.58MB 34.58MB +0.01% (2.17kB)
Type<'db>::cached_materialization_ 1.03MB 1.03MB +0.17% (1.81kB)
enum_metadata 1.17MB 1.17MB +0.13% (1.59kB)
infer_expression_types_impl 23.36MB 23.36MB +0.00% (1.19kB)
try_call_dunder_get_inner::interned_arguments 1.34MB 1.34MB +0.07% (1008.00B)
BoundMethodType 2.01MB 2.01MB +0.04% (880.00B)
... 33 more

sphinx

Name Old New Diff Outcome
protocol_member_names_by_structural_priority 0.00B 15.12kB +15.12kB (new)
protocol_apply_self_with_receiver::interned_arguments 435.50kB 432.25kB -0.75% (3.25kB) ⬇️
inherited_object_protocol_member_count 0.00B 2.41kB +2.41kB (new)
is_redundant_with_impl 764.19kB 766.09kB +0.25% (1.91kB)
BoundMethodType<'db>::bound_signatures_ 402.91kB 404.27kB +0.34% (1.35kB)
protocol_apply_self_with_receiver 170.08kB 168.83kB -0.73% (1.25kB) ⬇️
infer_scope_types_impl 6.10MB 6.10MB -0.01% (536.00B) ⬇️
member_lookup_with_policy_inner 4.80MB 4.80MB -0.01% (512.00B) ⬇️
Type<'db>::cached_materialization_::interned_arguments 375.08kB 375.55kB +0.12% (480.00B)
infer_expression_types_impl 11.42MB 11.42MB +0.00% (456.00B)
Type<'db>::cached_materialization_ 247.16kB 247.61kB +0.18% (456.00B)
Type<'db>::class_member_with_policy_inner_ 2.82MB 2.82MB -0.01% (376.00B) ⬇️
protocol_bind_self::interned_arguments 85.42kB 85.08kB -0.40% (352.00B) ⬇️
infer_definition_types 10.78MB 10.78MB -0.00% (312.00B) ⬇️
MemberLookupKey 2.95MB 2.95MB -0.01% (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.39MB 1.39MB +0.21% (2.95kB)
inherited_object_protocol_member_count 0.00B 1.04kB +1.04kB (new)
Type<'db>::cached_materialization_::interned_arguments 301.64kB 302.42kB +0.26% (800.00B)
infer_definition_types 4.43MB 4.43MB +0.02% (728.00B)
BoundTypeVarInstance 226.96kB 227.65kB +0.30% (704.00B)
Type<'db>::cached_materialization_ 210.46kB 211.12kB +0.32% (680.00B)
is_redundant_with_impl 325.45kB 326.10kB +0.20% (672.00B)
TypeVarInstance 73.22kB 73.78kB +0.77% (576.00B)
MaterializedProtocolType 12.59kB 12.87kB +2.23% (288.00B)
protocol_apply_self_with_receiver::interned_arguments 138.53kB 138.33kB -0.15% (208.00B) ⬇️
BoundMethodType<'db>::bound_signatures_ 197.54kB 197.69kB +0.08% (152.00B)
when_constraint_set_assignable_to_owned_impl 969.27kB 969.39kB +0.01% (128.00B)
MemberLookupKey 1.14MB 1.14MB -0.01% (104.00B) ⬇️
protocol_apply_self_with_receiver 54.52kB 54.45kB -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.54kB 294.09kB +0.19% (568.00B)
inherited_object_protocol_member_count 0.00B 168.00B +168.00B (new)
is_redundant_with_impl 82.04kB 82.20kB +0.20% (168.00B)
Type<'db>::class_member_with_policy_inner_ 261.88kB 262.04kB +0.06% (168.00B)
BoundMethodType<'db>::bound_signatures_ 40.16kB 40.30kB +0.37% (152.00B)
MemberLookupKey 276.91kB 277.02kB +0.04% (104.00B)
TypeVarInstance 22.31kB 22.41kB +0.42% (96.00B)
BoundTypeVarInstance 60.07kB 60.16kB +0.14% (88.00B)
protocol_bind_self::interned_arguments 15.47kB 15.55kB +0.56% (88.00B)
Type<'db>::cached_materialization_::interned_arguments 67.19kB 67.27kB +0.12% (80.00B)
remove_self_inner::interned_arguments 4.92kB 4.99kB +1.43% (72.00B)
MaterializedProtocolType 1.69kB 1.76kB +4.17% (72.00B)
member_lookup_with_policy_inner 322.05kB 322.12kB +0.02% (64.00B)
Type<'db>::cached_materialization_ 42.51kB 42.57kB +0.15% (64.00B)
... 10 more

@astral-sh-bot

astral-sh-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

Lint rule Added Removed Changed
unsound-return-statement 0 0 1
Total 0 0 1

Large timing changes:

Project Old Time New Time Change
colour 0.57s 1.25s +121%
DateType 0.06s 0.10s +54%

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

Raw diff:

meson (https://github.com/mesonbuild/meson)
- mesonbuild/compilers/mixins/visualstudio.py:392:16 warning[unsound-return-statement] Unsound return statement: `list[str] | list[str | Divergent]` is not a subtype of `list[str]`
+ mesonbuild/compilers/mixins/visualstudio.py:392:16 warning[unsound-return-statement] Unsound return statement: `list[str] | list[Divergent]` is not a subtype of `list[str]`

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 32.89%

⚠️ 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

❌ 3 regressed benchmarks
✅ 108 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] 579.8 ms 1,030.9 ms -43.76%
Simulation DateType 235.5 ms 405.4 ms -41.9%
Memory DateType 14.8 MB 16 MB -7.49%

Tip

Investigate this regression with the CodSpeed MCP and your agent.


Comparing alex/protocol-object-fallback (ed3c4fa) with main (9a908ef)

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