Skip to content

Commit 844b0eb

Browse files
committed
Merge from 3.x: PR #3576
Fixes #1373
2 parents 235ddb9 + c5434b4 commit 844b0eb

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

Diff for: spyder/widgets/sourcecode/codeeditor.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1957,8 +1957,10 @@ def fix_indent(self, forward=True, comment_or_string=False):
19571957
break
19581958
else:
19591959
if prevtext.strip():
1960-
prevexpr = re.split(r'\(|\{|\[', prevtext)[-1]
1961-
correct_indent = len(prevtext)-len(prevexpr)
1960+
if len(re.split(r'\(|\{|\[', prevtext)) > 1:
1961+
#correct indent only if there are still opening brackets
1962+
prevexpr = re.split(r'\(|\{|\[', prevtext)[-1]
1963+
correct_indent = len(prevtext)-len(prevexpr)
19621964
else:
19631965
correct_indent = len(prevtext)
19641966

Diff for: spyder/widgets/sourcecode/tests/test_autoindent.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ def test_def_with_indented_comment():
4949
text = get_indent_fix("def function():\n # Comment\n")
5050
assert text == "def function():\n # Comment\n ", repr(text)
5151

52+
def test_brackets_alone():
53+
text = get_indent_fix("def function():\n print []\n")
54+
assert text == "def function():\n print []\n ", repr(text)
5255

5356
# --- Failing tests
5457
# -----------------------------------------------------------------------------
@@ -70,11 +73,5 @@ def test_open_parenthesis():
7073
assert text == "open_parenthesis(\n ", repr(text)
7174

7275

73-
@pytest.mark.xfail
74-
def test_brackets_alone():
75-
text = get_indent_fix("def function():\n print []\n")
76-
assert text == "def function():\n print []\n ", repr(text)
77-
78-
7976
if __name__ == "__main__":
8077
pytest.main()

0 commit comments

Comments
 (0)