[Python-checkins] fix: use unambiguous punction in 'invalid escape sequence' message (GH-26582)
pablogsal
webhook-mailer at python.org
Mon Jun 7 20:15:55 EDT 2021
https://github.com/python/cpython/commit/ffd87b7093109c279caf8e3ca060f408a102388a
commit: ffd87b7093109c279caf8e3ca060f408a102388a
branch: main
author: Ned Batchelder <ned at nedbatchelder.com>
committer: pablogsal <Pablogsal at gmail.com>
date: 2021-06-08T01:15:46+01:00
summary:
fix: use unambiguous punction in 'invalid escape sequence' message (GH-26582)
files:
M Lib/test/test_cmd_line_script.py
M Parser/string_parser.c
diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py
index af29c171d4282f..6ffec918ebbd59 100644
--- a/Lib/test/test_cmd_line_script.py
+++ b/Lib/test/test_cmd_line_script.py
@@ -651,7 +651,7 @@ def test_syntaxerror_invalid_escape_sequence_multi_line(self):
stderr.splitlines()[-3:],
[ b' foo = """\\q"""',
b' ^^^^^^^^',
- b'SyntaxError: invalid escape sequence \\q'
+ b'SyntaxError: invalid escape sequence \'\\q\''
],
)
diff --git a/Parser/string_parser.c b/Parser/string_parser.c
index b919633ded8d9d..fa41a360c3fb5b 100644
--- a/Parser/string_parser.c
+++ b/Parser/string_parser.c
@@ -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;
More information about the Python-checkins
mailing list