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 w503 special case #511

Merged
merged 1 commit into from
Dec 16, 2019
Merged
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
10 changes: 8 additions & 2 deletions autopep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,8 +1295,14 @@ def fix_w503(self, result):
before_line[:comment_index], one_string_token,
before_line[comment_index + 1:])
else:
self.source[fix_target_line] = '{} {}{}'.format(
before_line[:bl], one_string_token, before_line[bl:])
if before_line[:bl].endswith("#"):
# special case
# see: https://github.com/hhatto/autopep8/issues/503
self.source[fix_target_line] = '{}{} {}'.format(
before_line[:bl-2], one_string_token, before_line[bl-2:])
else:
self.source[fix_target_line] = '{} {}{}'.format(
before_line[:bl], one_string_token, before_line[bl:])

def fix_w504(self, result):
(line_index, _, target) = get_index_offset_contents(result,
Expand Down
16 changes: 16 additions & 0 deletions test/test_autopep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -4452,6 +4452,22 @@ def test_w503_with_comment_double(self):
22222222 and # C2
333333333333 # C3
)
"""
with autopep8_context(line, options=['--select=W503']) as result:
self.assertEqual(fixed, result)

def test_w503_with_comment_with_only_comment_block_charactor(self):
line = """\
if (True #
and True
and True):
print(1)
"""
fixed = """\
if (True and #
True and
True):
print(1)
"""
with autopep8_context(line, options=['--select=W503']) as result:
self.assertEqual(fixed, result)
Expand Down