Skip to content

Commit aade1cc

Browse files
authored
bpo-395222: Correctly unparse unicode prefix in ast_unparse.c (GH-19512)
1 parent 96515e9 commit aade1cc

3 files changed

Lines changed: 5 additions & 0 deletions

File tree

Lib/test/test_future.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ def test_annotations(self):
153153
eq = self.assertAnnotationEqual
154154
eq('...')
155155
eq("'some_string'")
156+
eq("u'some_string'")
156157
eq("b'\\xa3'")
157158
eq('Name')
158159
eq('None')
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Correctly unparse explicit ``u`` prefix for strings when postponed
2+
evaluation for annotations activated. Patch by Batuhan Taskaya.

Python/ast_unparse.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,8 @@ append_ast_expr(_PyUnicodeWriter *writer, expr_ty e, int level)
875875
if (e->v.Constant.value == Py_Ellipsis) {
876876
APPEND_STR_FINISH("...");
877877
}
878+
APPEND_STR_IF(e->v.Constant.kind != NULL,
879+
PyUnicode_AS_DATA(e->v.Constant.kind));
878880
return append_ast_constant(writer, e->v.Constant.value);
879881
case JoinedStr_kind:
880882
return append_joinedstr(writer, e, false);

0 commit comments

Comments
 (0)