Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix degrade to case of --select=W --ignore=W503 #533

Merged
merged 3 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions autopep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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


Expand Down Expand Up @@ -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)
Expand Down
64 changes: 64 additions & 0 deletions test/test_autopep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -4597,6 +4597,70 @@ 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)
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'
fixed = '(width == 0\n + height == 0)\n'
Expand Down