Repository navigation
[flake8-simplify] Detect nested async with under sync parent (SIM117) - #27821
Merged
ntBre merged 3 commits intoSep 15, 2026
Merged
Conversation
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| SIM117 | 9 | 9 | 0 | 0 | 0 |
Linter (preview)
βΉοΈ ecosystem check detected linter changes. (+9 -0 violations, +0 -0 fixes in 2 projects; 57 projects unchanged)
prefecthq/prefect (+6 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --no-fix --output-format concise --preview
+ src/prefect/flow_engine.py:2026:13: multiple-with-statements [*] Use a single `with` statement with multiple contexts instead of nested `with` statements + tests/server/utilities/test_messaging.py:307:9: multiple-with-statements [*] Use a single `with` statement with multiple contexts instead of nested `with` statements + tests/server/utilities/test_messaging.py:321:9: multiple-with-statements [*] Use a single `with` statement with multiple contexts instead of nested `with` statements + tests/server/utilities/test_messaging.py:397:9: multiple-with-statements [*] Use a single `with` statement with multiple contexts instead of nested `with` statements + tests/workers/test_base_worker.py:4876:13: multiple-with-statements Use a single `with` statement with multiple contexts instead of nested `with` statements + tests/workers/test_base_worker.py:5365:13: multiple-with-statements [*] Use a single `with` statement with multiple contexts instead of nested `with` statements
home-assistant/core (+3 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --no-fix --output-format concise --preview
+ tests/util/test_timeout.py:126:9: multiple-with-statements Use a single `with` statement with multiple contexts instead of nested `with` statements + tests/util/test_timeout.py:308:9: multiple-with-statements Use a single `with` statement with multiple contexts instead of nested `with` statements + tests/util/test_timeout.py:318:9: multiple-with-statements Use a single `with` statement with multiple contexts instead of nested `with` statements
Changes by rule (1 rules affected)
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| multiple-with-statements | 9 | 9 | 0 | 0 | 0 |
ntBre
reviewed
Aug 18, 2026
ntBre
left a comment
Contributor
There was a problem hiding this comment.
Thanks, this looks good overall. I just had a few minor suggestions.
Contributor
Author
|
Addressed the review notes:
|
VedantMadane
force-pushed
the
fix/sim117-nested-async-under-sync
branch
from
August 22, 2026 13:21
c7db729 to
f20b3a8
Compare
SIM117 deferred to a single-statement with parent unconditionally, so nested async with bodies under a sync with (or the inverse) were never checked. Only skip the child when the parent can actually combine with it: same async/sync and neither side is an exempt standalone manager. Fixes astral-sh#27800 Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
Factor mergeable_child helper for parent deferral and child merge checks, move new regression fixtures to end of SIM117.py, and add a two-pair nested sync/async case. Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
VedantMadane
force-pushed
the
fix/sim117-nested-async-under-sync
branch
from
September 9, 2026 16:14
f20b3a8 to
38d695d
Compare
flake8-simplify] Detect nested async with under sync parent (SIM117)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Fixes a SIM117 false negative when nested
async withstatements sit under a syncwithparent (and the inverse).Previously, SIM117 skipped any
withwhose parent was itself a single-statementwith, so that nested cases were fixed top-to-bottom. That skip was unconditional, so a sync parent caused nested async bodies to be ignored even though sync/async contexts cannot be merged:The parent deferral now only applies when the parent can actually combine with the current statement: same
async/syncand neither side is an exempt standalone manager (asyncio.timeout, trio cancel scopes, etc.).Test plan
SIM117.pywith regression cases for:asyncio.timeoutparentcargo test -p ruff_linter --lib multiplewithstatementsFixes #27800