Skip to content
This repository was archived by the owner on Jan 13, 2026. It is now read-only.

Commit 2710b03

Browse files
committed
Correct whitespace handling for with item with parens
1 parent 263d33e commit 2710b03

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

rewrite/rewrite/python/_parser_visitor.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,9 @@ def visit_With(self, node):
469469

470470
if parenthesized and self._parentheses_stack and self._parentheses_stack[-1] is parens_handler:
471471
self._cursor += 1
472-
self._parentheses_stack.pop()
473-
resources_container = JContainer(
474-
items_prefix,
475-
resources,
476-
Markers.EMPTY
472+
resources_container = self._parentheses_stack.pop()[0](
473+
JContainer(items_prefix, resources, Markers.EMPTY),
474+
Space.EMPTY
477475
)
478476
else:
479477
resources_container = JContainer(

rewrite/tests/python/all/with_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def test_with_parens():
3232
rewrite_run(
3333
python(
3434
"""\
35-
with (open('/dev/null') as x):
35+
with (
36+
open('/dev/null') as x):
3637
pass
3738
"""
3839
)

0 commit comments

Comments
 (0)