Skip to content

Commit

Permalink
Merge c1f66e8 into ddc1fc4
Browse files Browse the repository at this point in the history
  • Loading branch information
hhatto committed Apr 11, 2020
2 parents ddc1fc4 + c1f66e8 commit e8dac5d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion autopep8.py
Expand Up @@ -67,6 +67,7 @@ class documentation for more information.
from ConfigParser import Error

import pycodestyle
from pycodestyle import STARTSWITH_INDENT_STATEMENT_REGEX


try:
Expand Down Expand Up @@ -1028,7 +1029,13 @@ def fix_e702(self, result, logical):
# https://docs.python.org/reference/compound_stmts.html
for line in logical_lines:
if (result['id'] == 'E702' and ':' in line
and STARTSWITH_DEF_REGEX.match(line)):
and STARTSWITH_INDENT_STATEMENT_REGEX.match(line)):
if self.options.verbose:
print(
'---> avoid fixing {error} with '
'other compound statements'.format(error=result['id']),
file=sys.stderr
)
return []

line_index = result['line'] - 1
Expand Down
9 changes: 9 additions & 0 deletions test/test_autopep8.py
Expand Up @@ -4017,6 +4017,15 @@ def test_e702_with_dict_semicolon(self):
with autopep8_context(line) as result:
self.assertEqual(fixed, result)

def test_e702_with_e701_and_only_select_e702_option(self):
line = """\
for i in range(3):
if i == 1: print i; continue
print i
"""
with autopep8_context(line, options=["--select=E702"]) as result:
self.assertEqual(line, result)

def test_e703_with_inline_comment(self):
line = 'a = 5; # inline comment\n'
fixed = 'a = 5 # inline comment\n'
Expand Down

0 comments on commit e8dac5d

Please sign in to comment.