From 2d88b55c631003a2b961f1cf105865f370a353f5 Mon Sep 17 00:00:00 2001 From: Hideo Hattori Date: Tue, 7 Apr 2020 19:36:56 +0900 Subject: [PATCH 1/3] add test for W503,504 more complex case --- test/test_autopep8.py | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/test_autopep8.py b/test/test_autopep8.py index ab05e53b..c443bcd8 100755 --- a/test/test_autopep8.py +++ b/test/test_autopep8.py @@ -4597,6 +4597,52 @@ def test_w503_with_line_comments(self): with autopep8_context(line, options=['--select=W503', '--ignore=E']) as result: self.assertEqual(fixed, result) + def test_ignore_only_w503_with_select_w(self): + line = """\ +a = ( + 11 + 22 + + 33 + + 44 + + 55 +) +""" + fixed = """\ +a = ( + 11 + 22 + + 33 + + 44 + + 55 +) +""" + with autopep8_context(line, options=['--select=W', '--ignore=W503']) as result: + self.assertEqual(fixed, result) + with autopep8_context(line, options=['--select=W5', '--ignore=W503']) as result: + self.assertEqual(fixed, result) + with autopep8_context(line, options=['--select=W50', '--ignore=W503']) as result: + self.assertEqual(fixed, result) + + def test_ignore_only_w504_with_select_w(self): + line = """\ +a = ( + 11 + 22 + + 33 + + 44 + + 55 +) +""" + fixed = """\ +a = ( + 11 + 22 + + 33 + + 44 + + 55 +) +""" + with autopep8_context(line, options=['--select=W', '--ignore=W504']) as result: + self.assertEqual(fixed, result) + with autopep8_context(line, options=['--select=W5', '--ignore=W504']) as result: + self.assertEqual(fixed, result) + def test_w504(self): line = '(width == 0 +\n height == 0)\n' fixed = '(width == 0\n + height == 0)\n' From 351a42332b7749b1aa97545b59cb28d857f7226c Mon Sep 17 00:00:00 2001 From: Hideo Hattori Date: Tue, 7 Apr 2020 20:43:51 +0900 Subject: [PATCH 2/3] fix degrade to case of --select=W --ignore=W503 --- autopep8.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/autopep8.py b/autopep8.py index 1cd41006..ab160188 100755 --- a/autopep8.py +++ b/autopep8.py @@ -3691,7 +3691,7 @@ def create_parser(): return parser -def _expand_codes(codes): +def _expand_codes(codes, ignore_codes): """expand to individual E/W codes""" ret = set() @@ -3705,13 +3705,27 @@ def _expand_codes(codes): ): is_conflict = True + is_ignore_w503 = "W503" in ignore_codes + is_ignore_w504 = "W504" in ignore_codes + for code in codes: if code == "W": - ret.update({"W1", "W2", "W3", "W503", "W505", "W6"}) + if is_ignore_w503 and is_ignore_w504: + ret.update({"W1", "W2", "W3", "W505", "W6"}) + elif is_ignore_w503: + ret.update({"W1", "W2", "W3", "W504", "W505", "W6"}) + else: + ret.update({"W1", "W2", "W3", "W503", "W505", "W6"}) elif code in ("W5", "W50"): - ret.update({"W503", "W505"}) + if is_ignore_w503 and is_ignore_w504: + ret.update({"W505"}) + elif is_ignore_w503: + ret.update({"W504", "W505"}) + else: + ret.update({"W503", "W505"}) elif not (code in ("W503", "W504") and is_conflict): ret.add(code) + return ret @@ -3762,7 +3776,11 @@ def parse_args(arguments, apply_config=False): parser.error('--max-line-length must be greater than 0') if args.select: - args.select = _expand_codes(_split_comma_separated(args.select)) + args.select = _expand_codes(_split_comma_separated(args.select), + ( + _split_comma_separated(args.ignore) + if args.ignore else [] + )) if args.ignore: args.ignore = _split_comma_separated(args.ignore) From a9193477f5d595b3310a942a62aaea604a6696a3 Mon Sep 17 00:00:00 2001 From: Hideo Hattori Date: Tue, 7 Apr 2020 21:09:27 +0900 Subject: [PATCH 3/3] add unit test: --ignore=E503,E504 case --- test/test_autopep8.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/test_autopep8.py b/test/test_autopep8.py index c443bcd8..fff02b11 100755 --- a/test/test_autopep8.py +++ b/test/test_autopep8.py @@ -4642,6 +4642,24 @@ def test_ignore_only_w504_with_select_w(self): self.assertEqual(fixed, result) with autopep8_context(line, options=['--select=W5', '--ignore=W504']) as result: self.assertEqual(fixed, result) + with autopep8_context(line, options=['--select=W50', '--ignore=W504']) as result: + self.assertEqual(fixed, result) + + def test_ignore_w503_and_w504_with_select_w(self): + line = """\ +a = ( + 11 + 22 + + 33 + + 44 + + 55 +) +""" + with autopep8_context(line, options=['--select=W', '--ignore=W503,W504']) as result: + self.assertEqual(line, result) + with autopep8_context(line, options=['--select=W5', '--ignore=W503,W504']) as result: + self.assertEqual(line, result) + with autopep8_context(line, options=['--select=W50', '--ignore=W503,W504']) as result: + self.assertEqual(line, result) def test_w504(self): line = '(width == 0 +\n height == 0)\n'