Skip to content

Collect return statements with a statement-only visitor - #29911

Merged
MichaReiser merged 2 commits into
mainfrom
micha/plr0911-count-returns
Nov 2, 2026
Merged

MichaReiser merged 2 commits into
mainfrom
micha/plr0911-count-returns

Conversation

@MichaReiser

@MichaReiser MichaReiser commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Summary

Eleven lint checks collect return statements from the current function. Their visitor now skips expressions as well as nested functions and classes. The annotation fixer keeps its existing visitor because it also needs to detect yield and yield from before suggesting a return type.

For PLR0911 alone, 196 calls with all stable rules enabled, this cuts instructions from 323,004 to 64,650 (βˆ’79.98%)

Test Plan

The existing Ruff linter unit suite passes with no snapshot changes.

@MichaReiser MichaReiser added performance Potential performance improvement linter Related to the Ruff linter labels Nov 2, 2026
@MichaReiser
MichaReiser added this pull request to stack #29912 November 2, 2026 15:39
@astral-automations-bot

astral-automations-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

ruff-ecosystem results

Linter (stable)

βœ… ecosystem check detected no linter changes.

Linter (preview)

βœ… ecosystem check detected no linter changes.

Formatter (stable)

βœ… ecosystem check detected no format changes.

Formatter (preview)

βœ… ecosystem check detected no format changes.

Linter (stable) Β· Linter (preview) Β· Formatter (stable) Β· Formatter (preview)


Results for 2344dd3 Β· Workflow run

@MichaReiser
MichaReiser force-pushed the micha/plr0911-count-returns branch from c437589 to 75ceec9 Compare November 2, 2026 16:22
@MichaReiser MichaReiser changed the title Count returns with a statement-only visitor (PLR0911) Skip expressions when collecting return statements Nov 2, 2026
@astral-automations-bot

astral-automations-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Memory usage report

Memory usage unchanged βœ…


Results for 2344dd3 Β· Workflow run

@astral-automations-bot

astral-automations-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

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


Results for 2344dd3 Β· Workflow run

@MichaReiser
MichaReiser force-pushed the micha/plr0911-count-returns branch from 75ceec9 to c437589 Compare November 2, 2026 16:32
@MichaReiser MichaReiser changed the title Skip expressions when collecting return statements Count returns with a statement-only visitor (PLR0911) Nov 2, 2026
@MichaReiser MichaReiser changed the title Count returns with a statement-only visitor (PLR0911) Collect return statements with a statement-only visitor Nov 2, 2026
}

#[derive(Default)]
struct ReturnTypeVisitor<'a> {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule also needs to know whether a body contains a generator expression. It's the only rule, which is why we inlined the expression-visiting implementation here

@MichaReiser
MichaReiser marked this pull request as ready for review November 2, 2026 17:04
@MichaReiser
MichaReiser merged commit d91a55f into main Nov 2, 2026
79 checks passed
@MichaReiser
MichaReiser deleted the micha/plr0911-count-returns branch November 2, 2026 17:27

This branch was previously deployed

1 inactive deployment
automations β€” 2344dd35 Deployed Nov 2, 2026 by MichaReiser via security-review / security review #96622
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

linter Related to the Ruff linter performance Potential performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants