Skip to content

[ruff] Treat yield before break from a terminal loop as terminal (RUF075)#25447

Merged
ntBre merged 1 commit into
astral-sh:mainfrom
anishgirianish:ruf075-break-terminal-25378
May 29, 2026
Merged

[ruff] Treat yield before break from a terminal loop as terminal (RUF075)#25447
ntBre merged 1 commit into
astral-sh:mainfrom
anishgirianish:ruf075-break-terminal-25378

Conversation

@anishgirianish

Copy link
Copy Markdown
Contributor

Summary

Closes #25378.

Extends the yield-before-return terminal check to also cover yield-before-break, but only when the enclosing loop is itself in a terminal position. break exits the innermost loop, so a yield right before it has no cleanup code after it in that case.

Test Plan

mdtest passes for fallible-context-manager.md across the new and existing cases

@astral-sh-bot astral-sh-bot Bot requested a review from ntBre May 29, 2026 07:35
@astral-sh-bot

astral-sh-bot Bot commented May 29, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre ntBre added rule Implementing or modifying a lint rule preview Related to preview mode features labels May 29, 2026

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me, thank you!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is awesome! Thank you for embracing the mdtests!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thank you so much :)

@ntBre ntBre changed the title [ruff] Treat yield before break from a terminal loop as terminal in RUF075 [ruff] Treat yield before break from a terminal loop as terminal in RUF075 May 29, 2026
@ntBre ntBre changed the title [ruff] Treat yield before break from a terminal loop as terminal in RUF075 [ruff] Treat yield before break from a terminal loop as terminal in RUF075 May 29, 2026
@ntBre ntBre changed the title [ruff] Treat yield before break from a terminal loop as terminal in RUF075 [ruff] Treat yield before break from a terminal loop as terminal (RUF075) May 29, 2026
@ntBre ntBre merged commit 35ee088 into astral-sh:main May 29, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Related to preview mode features rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fallible-context-manager (RUF075) - false positive when yield is inside for loop with no cleanup afterwards

2 participants