Skip to content

Commit

Permalink
Merge from 3.x: PR #4485
Browse files Browse the repository at this point in the history
Fixes #4481
  • Loading branch information
ccordoba12 committed May 17, 2017
2 parents 8734731 + b715868 commit 07f921c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions spyder/widgets/sourcecode/codeeditor.py
Expand Up @@ -1585,7 +1585,7 @@ def fix_indent(self, forward=True, comment_or_string=False):
not prevtext.strip().startswith('#') and prevtext) or
prevtext):

if not prevtext.strip().startswith('return') and \
if not "return" in prevtext.strip().split()[:1] and \
(prevtext.strip().endswith(')') or
prevtext.strip().endswith(']') or
prevtext.strip().endswith('}')):
Expand Down Expand Up @@ -1634,7 +1634,7 @@ def fix_indent(self, forward=True, comment_or_string=False):
(prevtext.endswith('continue') or
prevtext.endswith('break') or
prevtext.endswith('pass') or
(prevtext.strip().startswith("return") and
("return" in prevtext.strip().split()[:1] and
len(re.split(r'\(|\{|\[', prevtext)) ==
len(re.split(r'\)|\}|\]', prevtext)))):
# Unindent
Expand Down
8 changes: 8 additions & 0 deletions spyder/widgets/sourcecode/tests/test_autoindent.py
Expand Up @@ -156,6 +156,10 @@ def test_first_line():
("a = (a # some comment\n", "a = (a # some comment\n ", "test_inline_comment"),
("len(a) == 1\n", "len(a) == 1\n", "test_balanced_brackets_not_ending_in_bracket"),
("x = f(\n", "x = f(\n ", "test_short_open_bracket_not_hanging_indent"),
("def some_func():\n return 10\n", "def some_func():\n return 10\n",
"test_return"),
("def some_func():\n returns = 10\n", "def some_func():\n returns = 10\n ",
"test_return_not_keyword"),
pytest.mark.xfail(
("foo = 1 # Comment open parenthesis (\n",
Expand Down Expand Up @@ -194,6 +198,10 @@ def test_def_with_unindented_comment():
"test_commented_brackets"),
("s = a[(a['a'] == l) & (a['a'] == 1)]['a']\n", "s = a[(a['a'] == l) & (a['a'] == 1)]['a']\n",
"test_balanced_brackets"),
("def some_func():\n\treturn 10\n", "def some_func():\n\treturn 10\n",
"test_return"),
("def some_func():\n\treturns = 10\n", "def some_func():\n\treturns = 10\n\t",
"test_return_not_keyword"),
# Failing test
pytest.mark.xfail(
Expand Down

0 comments on commit 07f921c

Please sign in to comment.