Skip to content

[ty] Preserve overloads through callable protocol decorators#25806

Merged
charliermarsh merged 1 commit into
mainfrom
dhruv/callable-protocol-decorators
Jun 10, 2026
Merged

[ty] Preserve overloads through callable protocol decorators#25806
charliermarsh merged 1 commit into
mainfrom
dhruv/callable-protocol-decorators

Conversation

@dhruvmanila

@dhruvmanila dhruvmanila commented Jun 10, 2026

Copy link
Copy Markdown
Member

Summary

The workaround from #25030 only inspected function literals and direct Callable types. Polars types both decorators on LazyFrame.collect as an IdentityFunction protocol, so ty represented the decorator expressions as protocol instances and discarded the overload signatures.

This follow-up resolves the protocol's bound __call__ method through the existing callable upcast path, while retaining the strict Callable[P, R] -> Callable[P, R] signature check.

Fixes the remaining Polars example reported in astral-sh/ty#2278.

Test plan

Add a regression test case for it.

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

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

@astral-sh-bot

astral-sh-bot Bot commented Jun 10, 2026

Copy link
Copy Markdown

Memory usage report

Summary

Project Old New Diff Outcome
prefect 564.13MB 564.26MB +0.02% (129.20kB)
sphinx 207.56MB 207.60MB +0.02% (35.02kB)
trio 87.75MB 87.77MB +0.02% (16.64kB)
flake8 35.38MB 35.39MB +0.03% (10.47kB)

Significant changes

Click to expand detailed breakdown

prefect

Name Old New Diff Outcome
infer_definition_types 75.87MB 75.97MB +0.13% (102.31kB)
CallableType 2.69MB 2.70MB +0.35% (9.53kB)
BoundMethodType<'db>::bound_signatures_ 459.51kB 467.33kB +1.70% (7.82kB)
BoundMethodType<'db>::into_callable_type_ 231.00kB 234.45kB +1.49% (3.45kB)
infer_deferred_types 8.75MB 8.75MB +0.01% (1.24kB)
FunctionType<'db>::signature_ 2.94MB 2.93MB -0.04% (1.15kB)
member_lookup_with_policy_inner 13.53MB 13.53MB +0.01% (880.00B)
Type<'db>::class_member_with_policy_ 10.01MB 10.01MB +0.01% (712.00B)
ClassType<'db>::into_callable_ 9.35kB 9.92kB +6.14% (588.00B)
member_lookup_with_policy_inner::interned_arguments 6.68MB 6.68MB +0.01% (480.00B)
FunctionType 4.15MB 4.15MB +0.01% (432.00B)
GenericContext 334.06kB 334.47kB +0.12% (416.00B)
Type<'db>::class_member_with_policy_::interned_arguments 5.67MB 5.67MB +0.01% (416.00B)
enum_metadata 2.27MB 2.27MB +0.01% (208.00B)
is_redundant_with_impl::interned_arguments 2.37MB 2.37MB +0.01% (176.00B)
... 19 more

sphinx

Name Old New Diff Outcome
infer_definition_types 20.72MB 20.74MB +0.07% (13.89kB)
CallableType 1.36MB 1.37MB +0.58% (8.06kB)
BoundMethodType<'db>::bound_signatures_ 405.18kB 409.66kB +1.10% (4.48kB)
BoundMethodType<'db>::into_callable_type_ 211.80kB 213.61kB +0.85% (1.80kB)
infer_deferred_types 3.88MB 3.89MB +0.03% (1.21kB)
member_lookup_with_policy_inner 5.64MB 5.64MB +0.02% (1.09kB)
FunctionType<'db>::signature_ 1.79MB 1.79MB -0.05% (1.00kB)
ClassType<'db>::into_callable_ 3.71kB 4.49kB +21.18% (804.00B)
Type<'db>::class_member_with_policy_ 4.63MB 4.63MB +0.02% (800.00B)
FunctionType 1.58MB 1.58MB +0.05% (792.00B)
GenericContext 149.59kB 150.20kB +0.41% (624.00B)
member_lookup_with_policy_inner::interned_arguments 2.66MB 2.66MB +0.02% (600.00B)
Type<'db>::class_member_with_policy_::interned_arguments 2.29MB 2.29MB +0.02% (520.00B)
Type<'db>::apply_specialization_inner_ 1.52MB 1.52MB +0.02% (256.00B)
is_redundant_with_impl::interned_arguments 1.14MB 1.14MB +0.01% (176.00B)
... 13 more

trio

Name Old New Diff Outcome
infer_definition_types 6.61MB 6.61MB +0.08% (5.11kB)
CallableType 666.08kB 670.96kB +0.73% (4.88kB)
BoundMethodType<'db>::bound_signatures_ 95.48kB 97.24kB +1.85% (1.77kB)
infer_deferred_types 1.72MB 1.72MB +0.07% (1.23kB)
FunctionType<'db>::signature_ 746.04kB 745.16kB -0.12% (904.00B)
BoundMethodType<'db>::into_callable_type_ 52.83kB 53.65kB +1.55% (840.00B)
Type<'db>::class_member_with_policy_ 1.15MB 1.15MB +0.04% (504.00B)
member_lookup_with_policy_inner 1.42MB 1.42MB +0.03% (504.00B)
ClassType<'db>::into_callable_ 2.55kB 2.92kB +14.22% (372.00B)
member_lookup_with_policy_inner::interned_arguments 767.46kB 767.81kB +0.05% (360.00B)
Type<'db>::class_member_with_policy_::interned_arguments 616.59kB 616.89kB +0.05% (312.00B)
enum_metadata 205.16kB 205.36kB +0.10% (208.00B)
GenericContext 133.42kB 133.62kB +0.15% (208.00B)
is_redundant_with_impl::interned_arguments 224.73kB 224.90kB +0.08% (176.00B)
lookup_dunder_new_inner 34.27kB 34.42kB +0.42% (148.00B)
... 12 more

flake8

Name Old New Diff Outcome
CallableType 202.91kB 205.06kB +1.06% (2.16kB)
infer_definition_types 1.57MB 1.58MB +0.09% (1.49kB)
infer_deferred_types 428.26kB 429.47kB +0.28% (1.21kB)
member_lookup_with_policy_inner 404.51kB 405.30kB +0.20% (808.00B)
Type<'db>::class_member_with_policy_ 316.53kB 317.16kB +0.20% (652.00B)
ClassType<'db>::into_callable_ 372.00B 960.00B +158.06% (588.00B)
member_lookup_with_policy_inner::interned_arguments 201.80kB 202.27kB +0.23% (480.00B)
FunctionType 212.52kB 212.94kB +0.20% (432.00B)
Type<'db>::class_member_with_policy_::interned_arguments 163.41kB 163.82kB +0.25% (416.00B)
FunctionType<'db>::signature_ 278.53kB 278.88kB +0.13% (364.00B)
BoundMethodType<'db>::bound_signatures_ 32.45kB 32.66kB +0.67% (224.00B)
enum_metadata 55.82kB 56.02kB +0.36% (208.00B)
GenericContext 46.52kB 46.72kB +0.44% (208.00B)
is_redundant_with_impl::interned_arguments 89.89kB 90.06kB +0.19% (176.00B)
lookup_dunder_new_inner 12.79kB 12.94kB +1.13% (148.00B)
... 13 more

@astral-sh-bot

astral-sh-bot Bot commented Jun 10, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@dhruvmanila dhruvmanila marked this pull request as ready for review June 10, 2026 05:11
@charliermarsh charliermarsh merged commit 7d69b13 into main Jun 10, 2026
59 checks passed
@charliermarsh charliermarsh deleted the dhruv/callable-protocol-decorators branch June 10, 2026 12:13
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.

3 participants