From: Batuhan Taşkaya Date: Tue, 14 Apr 2020 18:55:01 +0000 (+0300) Subject: bpo-395222: Correctly unparse unicode prefix in ast_unparse.c (GH-19512) X-Git-Tag: v3.9.0a6~118 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=aade1cc453698e1bc48861b16955c2c2219ec521;p=thirdparty%2FPython%2Fcpython.git bpo-395222: Correctly unparse unicode prefix in ast_unparse.c (GH-19512) --- diff --git a/Lib/test/test_future.py b/Lib/test/test_future.py index ebeb833d7e25..0522003d3c9b 100644 --- a/Lib/test/test_future.py +++ b/Lib/test/test_future.py @@ -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 index 000000000000..12d939d05437 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-04-14-18-47-00.bpo-39522.uVeIV_.rst @@ -0,0 +1,2 @@ +Correctly unparse explicit ``u`` prefix for strings when postponed +evaluation for annotations activated. Patch by Batuhan Taskaya. diff --git a/Python/ast_unparse.c b/Python/ast_unparse.c index 7cf199b1b42d..c321acf99186 100644 --- a/Python/ast_unparse.c +++ b/Python/ast_unparse.c @@ -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);