]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-395222: Correctly unparse unicode prefix in ast_unparse.c (GH-19512)
authorBatuhan Taşkaya <batuhanosmantaskaya@gmail.com>
Tue, 14 Apr 2020 18:55:01 +0000 (21:55 +0300)
committerGitHub <noreply@github.com>
Tue, 14 Apr 2020 18:55:01 +0000 (19:55 +0100)
Lib/test/test_future.py
Misc/NEWS.d/next/Core and Builtins/2020-04-14-18-47-00.bpo-39522.uVeIV_.rst [new file with mode: 0644]
Python/ast_unparse.c

index ebeb833d7e25b029f43c591618aa439c1678d7a2..0522003d3c9b9717fdc04fd47e518eb98d185044 100644 (file)
@@ -153,6 +153,7 @@ class AnnotationsFutureTestCase(unittest.TestCase):
         eq = self.assertAnnotationEqual
         eq('...')
         eq("'some_string'")
+        eq("u'some_string'")
         eq("b'\\xa3'")
         eq('Name')
         eq('None')
diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-04-14-18-47-00.bpo-39522.uVeIV_.rst b/Misc/NEWS.d/next/Core and Builtins/2020-04-14-18-47-00.bpo-39522.uVeIV_.rst
new file mode 100644 (file)
index 0000000..12d939d
--- /dev/null
@@ -0,0 +1,2 @@
+Correctly unparse explicit ``u`` prefix for strings when postponed
+evaluation for annotations activated. Patch by Batuhan Taskaya.
index 7cf199b1b42d99a91bc367af15068390a900e05f..c321acf991864f35664d9627d330c7a2a84697bc 100644 (file)
@@ -875,6 +875,8 @@ append_ast_expr(_PyUnicodeWriter *writer, expr_ty e, int level)
         if (e->v.Constant.value == Py_Ellipsis) {
             APPEND_STR_FINISH("...");
         }
+        APPEND_STR_IF(e->v.Constant.kind != NULL,
+                      PyUnicode_AS_DATA(e->v.Constant.kind));
         return append_ast_constant(writer, e->v.Constant.value);
     case JoinedStr_kind:
         return append_joinedstr(writer, e, false);