Skip to content

Commit

Permalink
Fix removal of comments after dropped version block
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz committed Oct 10, 2024
1 parent 99f0d7a commit 7659c8c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyupgrade/_plugins/versioned_branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _fix_py2_block(i: int, tokens: list[Token]) -> None:


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


Expand Down
10 changes: 10 additions & 0 deletions tests/features/versioned_branches_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,16 @@ def test_fix_py3_only_code(s, expected):
id='elif becomes if',
),
pytest.param(
'import sys\n'
'if sys.version_info < (3, 6):\n'
' 3-5\n'
'# comment',
'import sys\n'
'# comment',
id='sys.version_info < (3, 6), trailing comment',
),
),
)
def test_fix_py3x_only_code(s, expected):
Expand Down

0 comments on commit 7659c8c

Please sign in to comment.