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 68e6854
Show file tree
Hide file tree
Showing 2 changed files with 22 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
21 changes: 21 additions & 0 deletions tests/features/versioned_branches_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,27 @@ 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',
),
pytest.param(
'import sys\n'
'if sys.version_info < (3, 6):\n'
' 3-5\n'
' # comment here\n'
'# comment there',
'import sys\n'
'# comment there',
id='sys.version_info < (3, 6), two comments',
),
),
)
def test_fix_py3x_only_code(s, expected):
Expand Down

0 comments on commit 68e6854

Please sign in to comment.