fix: use unambiguous punction in 'invalid escape sequence' message (GH-26582)

This commit is contained in:
Ned Batchelder 2021-06-07 20:15:46 -04:00 committed by GitHub
parent 165c884154
commit ffd87b7093
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -651,7 +651,7 @@ class CmdLineTest(unittest.TestCase):
stderr.splitlines()[-3:],
[ b' foo = """\\q"""',
b' ^^^^^^^^',
b'SyntaxError: invalid escape sequence \\q'
b'SyntaxError: invalid escape sequence \'\\q\''
],
)

View File

@ -12,7 +12,7 @@ static int
warn_invalid_escape_sequence(Parser *p, unsigned char first_invalid_escape_char, Token *t)
{
PyObject *msg =
PyUnicode_FromFormat("invalid escape sequence \\%c", first_invalid_escape_char);
PyUnicode_FromFormat("invalid escape sequence '\\%c'", first_invalid_escape_char);
if (msg == NULL) {
return -1;
}
@ -27,7 +27,7 @@ warn_invalid_escape_sequence(Parser *p, unsigned char first_invalid_escape_char,
since _PyPegen_raise_error uses p->tokens[p->fill - 1] for the
error location, if p->known_err_token is not set. */
p->known_err_token = t;
RAISE_SYNTAX_ERROR("invalid escape sequence \\%c", first_invalid_escape_char);
RAISE_SYNTAX_ERROR("invalid escape sequence '\\%c'", first_invalid_escape_char);
}
Py_DECREF(msg);
return -1;