Skip to content

Commit

Permalink
Merge pull request #532 from hhatto/fix-issue518
Browse files Browse the repository at this point in the history
both W503 and W504 are specified, priority is given to W503
  • Loading branch information
hhatto committed Apr 4, 2020
2 parents 7d9c1e1 + 1607835 commit 99611aa
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
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

0 comments on commit 99611aa

Please sign in to comment.