bpo-395222: Correctly unparse unicode prefix in ast_unparse.c (GH-19512)

This commit is contained in:
Batuhan Taşkaya 2020-04-14 21:55:01 +03:00 committed by GitHub
parent 96515e9f67
commit aade1cc453
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 0 deletions

View 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')

View File

@ -0,0 +1,2 @@
Correctly unparse explicit ``u`` prefix for strings when postponed
evaluation for annotations activated. Patch by Batuhan Taskaya.

View 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);