Merge pull request #3630 from laloch/fix-linecont

Fix ctx-free parser stripping the trailing newline
This commit is contained in:
Anthony Scopatz 2020-08-01 12:34:06 -05:00 committed by GitHub
commit a65b940992
Failed to generate hash of commit
3 changed files with 29 additions and 5 deletions

23
news/fix-linecont.rst Normal file
View file

@ -0,0 +1,23 @@
**Added:**
* <news item>
**Changed:**
* <news item>
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* Fixed syntax error in scripts containing line continuation syntax.
**Security:**
* <news item>

View file

@ -289,10 +289,11 @@ def _echo(args):
print(' '.join(args))
aliases['echo'] = _echo
echo --option1 \
echo --option1 \\
--option2
""",
"--option1 --option2\n",
echo missing \\
EOL""",
"--option1 --option2\nmissing EOL\n",
0,
),
#

View file

@ -242,6 +242,8 @@ class Execer(object):
last_error_line = e.loc.lineno
idx = last_error_line - 1
lines = input.splitlines()
if input.endswith("\n"):
lines.append("")
line, nlogical, idx = get_logical_line(lines, idx)
if nlogical > 1 and not logical_input:
_, sbpline = self._parse_ctx_free(
@ -254,8 +256,6 @@ class Execer(object):
last_error_col += 3
input = "\n".join(lines)
continue
if input.endswith("\n"):
lines.append("")
if len(line.strip()) == 0:
# whitespace only lines are not valid syntax in Python's
# interactive mode='single', who knew?! Just ignore them.