]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
fix: use unambiguous punction in 'invalid escape sequence' message (GH-26582) 26592/head
authorNed Batchelder <ned@nedbatchelder.com>
Tue, 8 Jun 2021 00:15:46 +0000 (20:15 -0400)
committerGitHub <noreply@github.com>
Tue, 8 Jun 2021 00:15:46 +0000 (01:15 +0100)
Lib/test/test_cmd_line_script.py
Parser/string_parser.c

index af29c171d4282f1b2cd8e9b95232cf00c5e22489..6ffec918ebbd5927acc575ec17ccd5e2cc1e179d 100644 (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\''
                 ],
             )
 
index b919633ded8d9d321391a70c17db8383e2d17b12..fa41a360c3fb5beed183f14263d30efcaf6e540f 100644 (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;