Skip to content

Commit

Permalink
Merge pull request #663 from hhatto/fix-issue662
Browse files Browse the repository at this point in the history
fix: e265, e266
  • Loading branch information
hhatto committed Dec 15, 2022
2 parents d0289ea + b7154f4 commit f75e8f6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion autopep8.py
Expand Up @@ -3330,7 +3330,7 @@ def filter_results(source, results, aggressive):
continue

if r['line'] in commented_out_code_line_numbers:
if issue_id.startswith(('e26', 'e501')):
if issue_id.startswith(('e261', 'e262', 'e501')):
continue

# Do not touch indentation if there is a token error caused by
Expand Down
23 changes: 20 additions & 3 deletions test/test_autopep8.py
Expand Up @@ -271,7 +271,7 @@ def test_format_block_comments_should_only_touch_real_comments(self):
commented_out_code = '#x = 1'
self.assertEqual(
commented_out_code,
fix_e265_and_e266(commented_out_code))
fix_e266(commented_out_code))

def test_fix_file(self):
self.assertIn(
Expand Down Expand Up @@ -2238,6 +2238,12 @@ def test_e265_only(self):
with autopep8_context(line, options=['--select=E265']) as result:
self.assertEqual(fixed, result)

def test_e265_issue662(self):
line = "#print(\" \")\n"
fixed = "# print(\" \")\n"
with autopep8_context(line, options=['--select=E265']) as result:
self.assertEqual(fixed, result)

def test_ignore_e265(self):
line = "## A comment\n#B comment\n123\n"
fixed = "# A comment\n#B comment\n123\n"
Expand All @@ -2256,6 +2262,12 @@ def test_e266_only(self):
with autopep8_context(line, options=['--select=E266']) as result:
self.assertEqual(fixed, result)

def test_e266_issue662(self):
line = "## comment\n"
fixed = "# comment\n"
with autopep8_context(line) as result:
self.assertEqual(fixed, result)

def test_ignore_e266(self):
line = "##A comment\n#B comment\n123\n"
fixed = "## A comment\n# B comment\n123\n"
Expand Down Expand Up @@ -3167,7 +3179,7 @@ def test_e501_with_comment(self):
# http://foo.bar/abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-
# The following is ugly commented-out code and should not be touched.
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = 1
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = 1
"""
with autopep8_context(line, options=['--aggressive']) as result:
self.assertEqual(fixed, result)
Expand Down Expand Up @@ -6442,7 +6454,7 @@ def test_e501_experimental_with_comment(self):
# http://foo.bar/abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-
# The following is ugly commented-out code and should not be touched.
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = 1
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = 1
"""
with autopep8_context(line, options=['--experimental',
'--aggressive']) as result:
Expand Down Expand Up @@ -7287,6 +7299,11 @@ def test_e501_experimental_with_in(self):
self.assertEqual(fixed, result)


def fix_e266(source):
with autopep8_context(source, options=['--select=E266']) as result:
return result


def fix_e265_and_e266(source):
with autopep8_context(source, options=['--select=E265,E266']) as result:
return result
Expand Down

0 comments on commit f75e8f6

Please sign in to comment.