From d8902eee51e6710794bd6bcce2c4be55253deb3d Mon Sep 17 00:00:00 2001 From: Hideo Hattori Date: Sat, 11 Apr 2020 15:45:22 +0900 Subject: [PATCH 1/4] fix incorrect E702 fixes with --select=E702 option --- autopep8.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/autopep8.py b/autopep8.py index 2ad359fb..49170db8 100755 --- a/autopep8.py +++ b/autopep8.py @@ -67,6 +67,7 @@ class documentation for more information. from ConfigParser import Error import pycodestyle +from pycodestyle import STARTSWITH_INDENT_STATEMENT_REGEX try: @@ -1028,7 +1029,14 @@ def fix_e702(self, result, logical): # https://docs.python.org/reference/compound_stmts.html for line in logical_lines: if (result['id'] == 'E702' and ':' in line - and STARTSWITH_DEF_REGEX.match(line)): + and STARTSWITH_INDENT_STATEMENT_REGEX.match(line)): + if self.options.verbose: + print( + '---> avoid fixing {error} with ' + 'other compound statements'.format(error=result['id'], + ine=result['line']), + file=sys.stderr + ) return [] line_index = result['line'] - 1 From 8aece2d7277ad980a5d8e47c5863253025fe8b7c Mon Sep 17 00:00:00 2001 From: Hideo Hattori Date: Sat, 11 Apr 2020 15:48:11 +0900 Subject: [PATCH 2/4] add unit test --- test/test_autopep8.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/test_autopep8.py b/test/test_autopep8.py index 56083994..5001f8f4 100755 --- a/test/test_autopep8.py +++ b/test/test_autopep8.py @@ -4017,6 +4017,15 @@ def test_e702_with_dict_semicolon(self): with autopep8_context(line) as result: self.assertEqual(fixed, result) + def test_e702_with_e701_and_only_select_e702_option(self): + line = """\ +for i in range(3): + if i == 1: print i; continue + print i +""" + with autopep8_context(line, options=["--select=E702"]) as result: + self.assertEqual(line, result) + def test_e703_with_inline_comment(self): line = 'a = 5; # inline comment\n' fixed = 'a = 5 # inline comment\n' From c1f66e8f1fde38b5e00e9fd59ee8b609404371c4 Mon Sep 17 00:00:00 2001 From: Hideo Hattori Date: Sat, 11 Apr 2020 15:59:22 +0900 Subject: [PATCH 3/4] remove unnecessary format's argument --- autopep8.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/autopep8.py b/autopep8.py index 49170db8..23f4ab60 100755 --- a/autopep8.py +++ b/autopep8.py @@ -1033,8 +1033,7 @@ def fix_e702(self, result, logical): if self.options.verbose: print( '---> avoid fixing {error} with ' - 'other compound statements'.format(error=result['id'], - ine=result['line']), + 'other compound statements'.format(error=result['id']), file=sys.stderr ) return [] From 761b0b06cd2998659c25ebeed8fa6c68c4ca6213 Mon Sep 17 00:00:00 2001 From: Hideo Hattori Date: Sat, 11 Apr 2020 16:14:01 +0900 Subject: [PATCH 4/4] add test for verbose log --- test/test_autopep8.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/test_autopep8.py b/test/test_autopep8.py index 5001f8f4..916b15b1 100755 --- a/test/test_autopep8.py +++ b/test/test_autopep8.py @@ -5284,6 +5284,19 @@ def test_verbose_diff(self): verbose_error = p.communicate()[1].decode('utf-8') self.assertIn('------------', verbose_error) + def test_verbose_with_select_e702(self): + line = """\ +for i in range(3): + if i == 1: print i; continue + print i +""" + with temporary_file_context(line) as filename: + p = Popen(list(AUTOPEP8_CMD_TUPLE) + + [filename, '-vvv', '--select=E702'], + stdout=PIPE, stderr=PIPE) + verbose_error = p.communicate()[1].decode('utf-8') + self.assertIn(" with other compound statements", verbose_error) + def test_in_place(self): line = "'abc' \n" fixed = "'abc'\n"