[issue40246] Different error messages for same error - invalid string prefixes

Serhiy Storchaka report at bugs.python.org
Wed Apr 29 02:50:26 EDT 2020


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

> It's no different from other edge cases where for some reason the space seems optional, like `1and 2`.

The parser is not consistent here. `0or[]` is an error, while `0and[]` and `1or[]` are valid. See https://mail.python.org/archives/list/python-dev@python.org/message/D2WPCITHG2LBQAP7DBTC6CY26WQUBAKP/

> A possible solution would be to only emit a SyntaxError if the NAME directly preceding a STRING token contains one of the valid string prefixes (either one of 'f', 'r', 'u', 'b').

This would not help for `if'a'<=x<='z'`. And we will get more breakage when add more string prefixes.

We should either require a whitespace between an identifier and a string literal (with SyntaxWarning in meantime) or allow to omit it.

----------

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


More information about the Python-bugs-list mailing list