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

incorrect E702 fixes with --select=E702 option #538

Merged
merged 4 commits into from Apr 11, 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
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
22 changes: 22 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 Expand Up @@ -5275,6 +5284,19 @@ def test_verbose_diff(self):
verbose_error = p.communicate()[1].decode('utf-8')
self.assertIn('------------', verbose_error)

def test_verbose_with_select_e702(self):
line = """\
for i in range(3):
if i == 1: print i; continue
print i
"""
with temporary_file_context(line) as filename:
p = Popen(list(AUTOPEP8_CMD_TUPLE) +
[filename, '-vvv', '--select=E702'],
stdout=PIPE, stderr=PIPE)
verbose_error = p.communicate()[1].decode('utf-8')
self.assertIn(" with other compound statements", verbose_error)

def test_in_place(self):
line = "'abc' \n"
fixed = "'abc'\n"
Expand Down