Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix removal of comments after dropped version block #971

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading