Skip to content

Commit

Permalink
Merge pull request #618 from hhatto/fix-issue-612
Browse files Browse the repository at this point in the history
fix e133 with case of no indentation
  • Loading branch information
hhatto authored Oct 21, 2021
2 parents bed5b56 + 35aa6d8 commit 68ad200
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions autopep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,11 @@ def fix_e131(self, result):

spaces_to_add = num_indent_spaces - len(_get_indentation(target))

indent_length = len(_get_indentation(target))
spaces_to_add = num_indent_spaces - indent_length
if num_indent_spaces == 0 and indent_length == 0:
spaces_to_add = 4

if spaces_to_add >= 0:
self.source[line_index] = (' ' * spaces_to_add +
self.source[line_index])
Expand Down
14 changes: 14 additions & 0 deletions test/test_autopep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,20 @@ def test_e133(self):
with autopep8_context(line, options=['--hang-closing']) as result:
self.assertEqual(fixed, result)

def test_e133_no_indentation_line(self):
line = """\
e = [
1, 2
]
"""
fixed = """\
e = [
1, 2
]
"""
with autopep8_context(line, options=['--hang-closing']) as result:
self.assertEqual(fixed, result)

def test_e133_not_effected(self):
line = """\
if True:
Expand Down

0 comments on commit 68ad200

Please sign in to comment.