[issue40847] New parser considers empty line following a backslash to be a syntax error, old parser didn't

Lysandros Nikolaou report at bugs.python.org
Fri Jun 5 21:23:28 EDT 2020


Lysandros Nikolaou <lisandrosnik at gmail.com> added the comment:

This is limited to cases where the line continuation character is on an otherwise empty line. For example this works correctly:

$ cat t.py
print("hello world")
print("hello world 2") \

print("hello world 3")
$ ./python.exe t.py
hello world
hello world 2
hello world 3

The actual problem is at the tokenizer level, where a line with only a continuation character is not considered an empty line and thus two NEWLINE tokens get emitted, one after the other. The old parser was somehow working around this, probably by having this in the grammar:

file_input: (NEWLINE | stmt)* ENDMARKER

The PEG parser OTOH does not allow this.

The question now is, is it reasonable to change the tokenizer to consider a lone backslash an empty line? Do you also consider this a bug? Or should we change the new parser?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40847>
_______________________________________


More information about the Python-bugs-list mailing list