bpo-40847: Consider a line with only a LINECONT a blank line (GH-20769)

A line with only a line continuation character should be considered
a blank line at tokenizer level so that only a single NEWLINE token
gets emitted. The old parser was working around the issue, but the
new parser threw a `SyntaxError` for valid input. For example,
an empty line following a line continuation character was interpreted
as a `SyntaxError`.

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
(cherry picked from commit 896f4cf63f)

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
This commit is contained in:
Miss Islington (bot) 2020-06-10 17:14:16 -07:00 committed by GitHub
parent 18e07ba931
commit e3ce3bba92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 1 deletions

View file

@ -854,6 +854,20 @@ class SyntaxTestCase(unittest.TestCase):
"iterable argument unpacking follows "
"keyword argument unpacking")
def test_empty_line_after_linecont(self):
# See issue-40847
s = r"""\
pass
\
pass
"""
try:
compile(s, '<string>', 'exec')
except SyntaxError:
self.fail("Empty line after a line continuation character is valid.")
def test_main():
support.run_unittest(SyntaxTestCase)
from test import test_syntax