Skip to content

Commit

Permalink
Merge pull request #466 from asottile/ignore_conflict
Browse files Browse the repository at this point in the history
Don't allow setting --ignore to enable conflicting fixes
  • Loading branch information
hhatto authored Jan 30, 2019
2 parents a1176ea + 9f4b8c9 commit 9b49c3a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions autopep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class documentation for more information.

DEFAULT_IGNORE = 'E226,E24,W50,W690' # TODO: use pycodestyle.DEFAULT_IGNORE
DEFAULT_INDENT_SIZE = 4
# these fixes conflict with each other, if the `--ignore` setting causes both
# to be enabled, disable both of them
CONFLICTING_CODES = ('W503', 'W504')

SELECTED_GLOBAL_FIXED_METHOD_CODES = ['W602', ]

Expand Down Expand Up @@ -3680,6 +3683,14 @@ def parse_args(arguments, apply_config=False):

if args.ignore:
args.ignore = _split_comma_separated(args.ignore)
if not all(
any(
conflicting_code.startswith(ignore_code)
for ignore_code in args.ignore
)
for conflicting_code in CONFLICTING_CODES
):
args.ignore.update(CONFLICTING_CODES)
elif not args.select:
if args.aggressive:
# Enable everything by default if aggressive.
Expand Down
18 changes: 18 additions & 0 deletions test/test_autopep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -4489,6 +4489,24 @@ def test_w504_with_line_comment(self):
with autopep8_context(line, options=['--select=W504', '--ignore=E']) as result:
self.assertEqual(fixed, result)

def test_w504_not_applied_by_default_when_modifying_with_ignore(self):
line = """\
q = 1
def x(y, z):
if (
y and
z
):
pass
"""
fixed = line.replace('\n\n\n\n', '\n\n')
with autopep8_context(line, options=['--ignore=E265']) 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 9b49c3a

Please sign in to comment.