summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBatuhan Taşkaya <batuhanosmantaskaya@gmail.com>2020-04-14 18:55:01 (GMT)
committerGitHub <noreply@github.com>2020-04-14 18:55:01 (GMT)
commitaade1cc453698e1bc48861b16955c2c2219ec521 (patch)
treeb61a4c6cbcf79811cbd51c71da43597c9f54634f
parent96515e9f6785328c52ebc5d4ce60e0087a9adc2d (diff)
downloadcpython-aade1cc453698e1bc48861b16955c2c2219ec521.zip
cpython-aade1cc453698e1bc48861b16955c2c2219ec521.tar.gz
cpython-aade1cc453698e1bc48861b16955c2c2219ec521.tar.bz2
bpo-395222: Correctly unparse unicode prefix in ast_unparse.c (GH-19512)
-rw-r--r--Lib/test/test_future.py1
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2020-04-14-18-47-00.bpo-39522.uVeIV_.rst2
-rw-r--r--Python/ast_unparse.c2
3 files changed, 5 insertions, 0 deletions
diff --git a/Lib/test/test_future.py b/Lib/test/test_future.py
index ebeb833..0522003 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 0000000..12d939d
--- /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 7cf199b..c321acf 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);