From 0e3303180ec39a1374862ddc3f2d3f44140cf294 Mon Sep 17 00:00:00 2001 From: Hideo Hattori Date: Thu, 25 Oct 2018 23:42:21 +0900 Subject: [PATCH] fix w503 with comment into pointed out line (for #446) --- autopep8.py | 4 ++++ test/test_autopep8.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/autopep8.py b/autopep8.py index 307c6711..70d63ab7 100755 --- a/autopep8.py +++ b/autopep8.py @@ -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 diff --git a/test/test_autopep8.py b/test/test_autopep8.py index 3ad067f6..26846598 100755 --- a/test/test_autopep8.py +++ b/test/test_autopep8.py @@ -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 = """\ (