[Python-checkins] cpython (merge 3.6 -> default): Merge from 3.6.

eric.smith python-checkins at python.org
Mon Nov 7 17:58:09 EST 2016


https://hg.python.org/cpython/rev/983a8887a895
changeset:   104960:983a8887a895
parent:      104958:d0e4440a68b3
parent:      104959:31543f7cbdf4
user:        Eric V. Smith <eric at trueblade.com>
date:        Mon Nov 07 17:57:48 2016 -0500
summary:
  Merge from 3.6.

files:
  Lib/test/test_fstring.py |  7 +++++++
  Python/ast.c             |  9 +++++----
  2 files changed, 12 insertions(+), 4 deletions(-)


diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py
--- a/Lib/test/test_fstring.py
+++ b/Lib/test/test_fstring.py
@@ -92,6 +92,13 @@
         exec(c)
         self.assertEqual(x[0], 'foo3')
 
+    def test_compile_time_concat_errors(self):
+        self.assertAllRaise(SyntaxError,
+                            'cannot mix bytes and nonbytes literals',
+                            [r"""f'' b''""",
+                             r"""b'' f''""",
+                             ])
+
     def test_literal(self):
         self.assertEqual(f'', '')
         self.assertEqual(f'a', 'a')
diff --git a/Python/ast.c b/Python/ast.c
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -5147,7 +5147,8 @@
         /* Check that we're not mixing bytes with unicode. */
         if (i != 0 && bytesmode != this_bytesmode) {
             ast_error(c, n, "cannot mix bytes and nonbytes literals");
-            Py_DECREF(s);
+            /* s is NULL if the current string part is an f-string. */
+            Py_XDECREF(s);
             goto error;
         }
         bytesmode = this_bytesmode;
@@ -5161,11 +5162,12 @@
             if (result < 0)
                 goto error;
         } else {
+            /* A string or byte string. */
+            assert(s != NULL && fstr == NULL);
+
             assert(bytesmode ? PyBytes_CheckExact(s) :
                    PyUnicode_CheckExact(s));
 
-            /* A string or byte string. */
-            assert(s != NULL && fstr == NULL);
             if (bytesmode) {
                 /* For bytes, concat as we go. */
                 if (i == 0) {
@@ -5177,7 +5179,6 @@
                         goto error;
                 }
             } else {
-                assert(s != NULL && fstr == NULL);
                 /* This is a regular string. Concatenate it. */
                 if (FstringParser_ConcatAndDel(&state, s) < 0)
                     goto error;

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list