('dict_comp', '{x:1 for x in a}'),
('dict_comp_if', '{x:1+2 for x in a if b}'),
('dict_empty', '{}'),
+ ('empty_line_after_linecont',
+ r'''
+ pass
+ \
+
+ pass
+ '''),
('for',
'''
for i in a:
"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
--- /dev/null
+Fix a bug where a line with only a line continuation character is not considered a blank line at tokenizer level.\r
+In such cases, more than a single `NEWLINE` token was emitted. The old parser was working around the issue,\r
+but the new parser threw a :exc:`SyntaxError` for valid input due to this. For example, an empty line following\r
+a line continuation character was interpreted as a :exc:`SyntaxError`. \r
}
}
tok_backup(tok, c);
- if (c == '#' || c == '\n') {
+ if (c == '#' || c == '\n' || c == '\\') {
/* Lines with only whitespace and/or comments
+ and/or a line continuation character
shouldn't affect the indentation and are
not passed to the parser as NEWLINE tokens,
except *totally* empty lines in interactive