Skip to content

[ty] Share parameter-default inference between functions and lambdas - #29078

Open
charliermarsh wants to merge 1 commit into
charlie/ty-stable-lambda-identitiesfrom
charlie/fix-ty-4613
Open

charliermarsh wants to merge 1 commit into
charlie/ty-stable-lambda-identitiesfrom
charlie/fix-ty-4613

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Summary

We already infer defaults for named functions separately from their annotations. Call checking only needs to know whether a parameter has a default, and evaluating its value while building the signature can re-enter the decorated function's own signature inference.

We now extend this separation to lambdas, using a shared inference region for each parameter default. Previously, reading a lambda default could infer its entire enclosing scope, causing recursive decorators to grow nested container types without converging.

Closes astral-sh/ty#4613.

@charliermarsh charliermarsh added the bug An issue describing something that isn't working, or a PR that fixes a bug label Oct 2, 2026
@charliermarsh
charliermarsh requested a review from a team as a code owner October 2, 2026 18:04
@charliermarsh charliermarsh added the ty The ty type checker label Oct 2, 2026
@astral-sh-bot
astral-sh-bot Bot requested a review from carljm October 2, 2026 18:04
@astral-sh-bot

astral-sh-bot Bot commented Oct 2, 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 98.24%. The percentage of expected errors that received a diagnostic held steady at 98.24%. The number of fully passing files held steady at 134/146.

@astral-sh-bot

astral-sh-bot Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Memory usage report

Summary

Project Old New Diff Outcome
prefect 476.02MB 476.40MB +0.08% (383.15kB) ⏫
sphinx 172.45MB 172.47MB +0.01% (21.68kB) ⏫
trio 93.09MB 93.10MB +0.01% (12.09kB) ⏫
flake8 38.29MB 38.30MB +0.01% (2.29kB) ⏫

Significant changes

Click to expand detailed breakdown

prefect

Name Old New Diff Outcome
infer_parameter_default_types 0.00B 905.33kB +905.33kB (new) ⏫
infer_function_default_types 551.86kB 0.00B -100.00% (551.86kB) ⬇️
infer_scope_types_impl 19.68MB 19.71MB +0.17% (33.88kB) ⏫
parameter_default_type 26.09kB 24.41kB -6.44% (1.68kB) ⬇️
infer_definition_types 37.85MB 37.85MB -0.00% (632.00B) ⬇️
infer_lambda_signature 285.37kB 284.93kB -0.15% (448.00B) ⬇️
infer_expression_types_impl 24.06MB 24.06MB -0.00% (432.00B) ⬇️
TypePair 9.02MB 9.02MB -0.00% (384.00B) ⬇️
UnionType 1.38MB 1.38MB -0.02% (224.00B) ⬇️
infer_statement_types_impl 674.94kB 674.73kB -0.03% (216.00B) ⬇️
is_redundant_with_impl 3.10MB 3.10MB -0.00% (160.00B) ⬇️
union_from_two_elements 222.51kB 222.41kB -0.04% (96.00B) ⬇️

sphinx

Name Old New Diff Outcome
infer_parameter_default_types 0.00B 109.55kB +109.55kB (new) ⏫
infer_function_default_types 91.18kB 0.00B -100.00% (91.18kB) ⬇️
infer_scope_types_impl 6.20MB 6.21MB +0.05% (3.32kB) ⏫
parameter_default_type 272.00B 256.00B -5.88% (16.00B) ⬇️

trio

Name Old New Diff Outcome
infer_parameter_default_types 0.00B 61.18kB +61.18kB (new) ⏫
infer_function_default_types 50.33kB 0.00B -100.00% (50.33kB) ⬇️
infer_scope_types_impl 2.83MB 2.84MB +0.06% (1.67kB) ⏫
parameter_default_type 5.16kB 4.73kB -8.32% (440.00B) ⬇️

flake8

Name Old New Diff Outcome
infer_parameter_default_types 0.00B 7.05kB +7.05kB (new) ⏫
infer_function_default_types 4.98kB 0.00B -100.00% (4.98kB) ⬇️
infer_scope_types_impl 536.13kB 536.37kB +0.04% (240.00B) ⏫
parameter_default_type 72.00B 64.00B -11.11% (8.00B) ⬇️

@astral-sh-bot

astral-sh-bot Bot commented Oct 2, 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)

@charliermarsh
charliermarsh marked this pull request as draft October 2, 2026 18:15
@charliermarsh charliermarsh changed the title [ty] Preserve cycles containing provisional inference markers [ty] Infer lambda defaults independently of their enclosing scope Oct 2, 2026
@charliermarsh charliermarsh changed the title [ty] Infer lambda defaults independently of their enclosing scope [ty] Share parameter-default inference between functions and lambdas Oct 2, 2026
@charliermarsh
charliermarsh added this pull request to stack #29081 October 2, 2026 20:57
@codspeed

codspeed Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 178 untouched benchmarks
⏩ 60 skipped benchmarks1


Comparing charlie/fix-ty-4613 (4c829ad) with charlie/ty-stable-lambda-identities (b21c1ae)

Open in CodSpeed

Footnotes

  1. 60 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. ↩

@charliermarsh
charliermarsh marked this pull request as ready for review October 2, 2026 21:24

This branch had an error being deployed

1 failed deployment
automations — 4c829ad8 Deployed Oct 7, 2026 by charliermarsh via security-review / security review #90909
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An issue describing something that isn't working, or a PR that fixes a bug ty The ty type checker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ty hangs on a decorated class defined in a while loop

1 participant