From 5bb4781baeb081baae7dcfc9bddc198fd37346ad Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Mon, 4 Feb 2019 18:00:21 -0500 Subject: [PATCH 1/2] fixed indentation errors --- news/linecont.rst | 24 ++++++++++++++++++++++++ tests/test_execer.py | 1 + xonsh/execer.py | 6 ++++++ xonsh/tools.py | 10 ++++++++++ 4 files changed, 41 insertions(+) create mode 100644 news/linecont.rst diff --git a/news/linecont.rst b/news/linecont.rst new file mode 100644 index 000000000..eb5f1e21e --- /dev/null +++ b/news/linecont.rst @@ -0,0 +1,24 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Fixed regression with line continuations in implicit subprocess mode within + indented blocks of code, such as if-statements. + +**Security:** + +* diff --git a/tests/test_execer.py b/tests/test_execer.py index 75dc205e5..22e612a6d 100644 --- a/tests/test_execer.py +++ b/tests/test_execer.py @@ -133,6 +133,7 @@ def test_echo_line_cont(): "echo a and \\\necho b\n", "echo a \\\n or echo b\n", "echo a \\\n or echo b and \\\n echo c\n", + "if True:\\\n echo a \\\n b\n", ], ) def test_two_echo_line_cont(code): diff --git a/xonsh/execer.py b/xonsh/execer.py index d46b290eb..7283e8b9a 100644 --- a/xonsh/execer.py +++ b/xonsh/execer.py @@ -14,6 +14,7 @@ from xonsh.tools import ( get_logical_line, replace_logical_line, balanced_parens, + starting_whitespace, ) from xonsh.built_ins import load_builtins, unload_builtins, load_proxies, unload_proxies @@ -207,6 +208,9 @@ class Execer(object): greedy = False if filename is None: filename = self.filename + if logical_input: + beg_spaces = starting_whitespace(input) + input = input[len(beg_spaces):] while not parsed: try: tree = self.parser.parse( @@ -313,4 +317,6 @@ class Execer(object): replace_logical_line(lines, sbpline, idx, nlogical) last_error_col += 3 input = "\n".join(lines) + if logical_input: + input = beg_spaces + input return tree, input diff --git a/xonsh/tools.py b/xonsh/tools.py index 0347cc502..58fad0323 100644 --- a/xonsh/tools.py +++ b/xonsh/tools.py @@ -616,6 +616,16 @@ def subexpr_before_unbalanced(expr, ltok, rtok): return subexpr +@lazyobject +def STARTING_WHITESPACE_RE(): + return re.compile(r"^(\s*)") + + +def starting_whitespace(s): + """Returns the whitespace at the start of a string""" + return STARTING_WHITESPACE_RE.match(s).group(1) + + def decode(s, encoding=None): encoding = encoding or DEFAULT_ENCODING return s.decode(encoding, "replace") From 9ec27c32f133b359cb81e2561bbdf95f67381d69 Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Mon, 4 Feb 2019 18:02:20 -0500 Subject: [PATCH 2/2] black --- xonsh/execer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xonsh/execer.py b/xonsh/execer.py index 7283e8b9a..1815a5b91 100644 --- a/xonsh/execer.py +++ b/xonsh/execer.py @@ -210,7 +210,7 @@ class Execer(object): filename = self.filename if logical_input: beg_spaces = starting_whitespace(input) - input = input[len(beg_spaces):] + input = input[len(beg_spaces) :] while not parsed: try: tree = self.parser.parse(