Skip to content

Commit

Permalink
fix w503 with comment into pointed out line (for #446)
Browse files Browse the repository at this point in the history
  • Loading branch information
hhatto committed Oct 25, 2018
1 parent 46af2bc commit 0e33031
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions autopep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,10 @@ def fix_w503(self, result):
tts = ts
old = None
for t in tts:
if t[0] in (tokenize.NEWLINE, tokenize.NL):
newline_count -= 1
if newline_count <= 1:
break
if tokenize.COMMENT == t[0] and old and old[0] != tokenize.NL:
comment_index = old[3][1]
break
Expand Down
18 changes: 18 additions & 0 deletions test/test_autopep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -4302,6 +4302,24 @@ def test_w503_with_comment(self):
with autopep8_context(line, options=['--select=W503']) as result:
self.assertEqual(fixed, result)

def test_w503_with_comment_into_point_out_line(self):
line = """\
def test():
return (
True not in []
and False # comment required
)
"""
fixed = """\
def test():
return (
True not in [] and
False # comment required
)
"""
with autopep8_context(line, options=['--select=W503']) as result:
self.assertEqual(fixed, result)

def test_w503_with_comment_double(self):
line = """\
(
Expand Down

0 comments on commit 0e33031

Please sign in to comment.