You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Collect return statements with a statement-only visitor - #29911
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
changed the title
Count returns with a statement-only visitor (PLR0911)
Collect return statements with a statement-only visitor
Nov 2, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
linterRelated to the Ruff linterperformancePotential performance improvement
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Eleven lint checks collect
returnstatements 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 detectyieldandyield frombefore 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.