Visitar URL original
[ty] Generalize nested types in inferred return types by sharkdp · Pull Request #29488 · astral-sh/ruff · GitHub
Skip to content

[ty] Generalize nested types in inferred return types - #29488

Merged
sharkdp merged 2 commits into
mainfrom
david/rti-nested-types
Oct 22, 2026
Merged

sharkdp merged 2 commits into
mainfrom
david/rti-nested-types

Conversation

@sharkdp

@sharkdp sharkdp commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Generalize/promote types in inferred return types that refer to local nested definitions.

For example, consider this unannotated decorator:

 def register(event: str):
     def wrapper(func):
         # ...
         return func

     return wrapper

We do not want to infer def wrapper(func) -> Unknown as the return type of register. This would not just expose internal details, it would also incorrectly suggest that each call to register returns the same function object. Instead, we generalize to an anonymous (func) -> Unknown callable.

For nested classes, we cannot easily do the same, so we return Unknown instead. In the future, to improve this, we might want to synthesize a protocol that has the same attributes and methods as the nested class.

Test strategy

Updated existing mdtests

@sharkdp sharkdp added bug An issue describing something that isn't working, or a PR that fixes a bug ty The ty type checker labels Oct 19, 2026
@astral-sh-bot

astral-sh-bot Bot commented Oct 19, 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 19, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

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

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@sharkdp sharkdp removed the bug An issue describing something that isn't working, or a PR that fixes a bug label Oct 19, 2026
@sharkdp sharkdp changed the title [ty] Generalize local types in inferred return types [ty] Generalize local local types in inferred return types Oct 20, 2026
@sharkdp
sharkdp force-pushed the david/rti-nested-types branch from b9e3673 to e49b033 Compare October 20, 2026 11:52
@sharkdp sharkdp changed the title [ty] Generalize local local types in inferred return types [ty] Generalize nested types in inferred return types Oct 20, 2026
@sharkdp
sharkdp marked this pull request as ready for review October 20, 2026 11:54
@sharkdp
sharkdp requested review from a team as code owners October 20, 2026 11:54
@astral-sh-bot
astral-sh-bot Bot requested a review from ibraheemdev October 20, 2026 11:54
@sharkdp
sharkdp merged commit 59a9e85 into main Oct 22, 2026
76 checks passed
@sharkdp
sharkdp deleted the david/rti-nested-types branch October 22, 2026 14:52

This branch was previously deployed

1 inactive deployment
automations — e49b0335 Deployed Oct 20, 2026 by sharkdp via security-review / security review #92311
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty The ty type checker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants