Skip to content

Commit 7659c8c

Browse files
committed
Fix removal of comments after dropped version block
1 parent 99f0d7a commit 7659c8c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pyupgrade/_plugins/versioned_branches.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _fix_py2_block(i: int, tokens: list[Token]) -> None:
4646

4747

4848
def _fix_remove_block(i: int, tokens: list[Token]) -> None:
49-
block = Block.find(tokens, i)
49+
block = Block.find(tokens, i, trim_end=True)
5050
del tokens[block.start:block.end]
5151

5252

tests/features/versioned_branches_test.py

+10
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,16 @@ def test_fix_py3_only_code(s, expected):
607607
608608
id='elif becomes if',
609609
),
610+
pytest.param(
611+
'import sys\n'
612+
'if sys.version_info < (3, 6):\n'
613+
' 3-5\n'
614+
'# comment',
615+
616+
'import sys\n'
617+
'# comment',
618+
id='sys.version_info < (3, 6), trailing comment',
619+
),
610620
),
611621
)
612622
def test_fix_py3x_only_code(s, expected):

0 commit comments

Comments
 (0)