Skip to content

Commit

Permalink
fix w503 sepecial case (for #503)
Browse files Browse the repository at this point in the history
  • Loading branch information
hhatto committed Dec 5, 2019
1 parent 736fe7c commit 677d6fb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
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

0 comments on commit 677d6fb

Please sign in to comment.