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

both W503 and W504 are specified, priority is given to W503 #532

Merged
merged 3 commits into from Apr 4, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 25 additions & 1 deletion autopep8.py
Expand Up @@ -3691,6 +3691,30 @@ def create_parser():
return parser


def _expand_codes(codes):
"""expand to individual E/W codes"""
ret = set()

is_conflict = False
if all(
any(
conflicting_code.startswith(code)
for code in codes
)
for conflicting_code in CONFLICTING_CODES
):
is_conflict = True

for code in codes:
if code == "W":
ret.update({"W1", "W2", "W3", "W503", "W505", "W6"})
elif code in ("W5", "W50"):
ret.update({"W503", "W505"})
elif not (code in ("W503", "W504") and is_conflict):
ret.add(code)
return ret


def parse_args(arguments, apply_config=False):
"""Parse command-line options."""
parser = create_parser()
Expand Down Expand Up @@ -3738,7 +3762,7 @@ def parse_args(arguments, apply_config=False):
parser.error('--max-line-length must be greater than 0')

if args.select:
args.select = _split_comma_separated(args.select)
args.select = _expand_codes(_split_comma_separated(args.select))

if args.ignore:
args.ignore = _split_comma_separated(args.ignore)
Expand Down
23 changes: 23 additions & 0 deletions test/test_autopep8.py
Expand Up @@ -4665,6 +4665,29 @@ def x(y, z):
with autopep8_context(line, options=['--ignore=E265']) as result:
self.assertEqual(fixed, result)

def test_w503_and_w504_conflict(self):
line = """\
if True:
if True:
assert_equal(self.nodes[0].getbalance(
), bal + Decimal('50.00000000') + Decimal('2.19000000')) # block reward + tx
"""
fixed = """\
if True:
if True:
assert_equal(
self.nodes[0].getbalance(),
bal +
Decimal('50.00000000') +
Decimal('2.19000000')) # block reward + tx
"""
with autopep8_context(line, options=['-aa', '--select=E,W']) as result:
self.assertEqual(fixed, result)
with autopep8_context(line, options=['-aa', '--select=E,W5']) as result:
self.assertEqual(fixed, result)
with autopep8_context(line, options=['-aa', '--select=E,W50']) as result:
self.assertEqual(fixed, result)

def test_w601(self):
line = 'a = {0: 1}\na.has_key(0)\n'
fixed = 'a = {0: 1}\n0 in a\n'
Expand Down