Skip to content

Commit b9bac0e

Browse files
committed
Simplify ast_unparase.c further
1 parent b81a807 commit b9bac0e

File tree

1 file changed

+4
-31
lines changed

1 file changed

+4
-31
lines changed

Python/ast_unparse.c

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -663,27 +663,15 @@ build_ftstring_body(asdl_expr_seq *values, bool is_format_spec)
663663
}
664664

665665
static int
666-
_write_values_subarray(PyUnicodeWriter *writer, asdl_expr_seq *values, Py_ssize_t first_idx,
667-
Py_ssize_t last_idx, char prefix, PyArena *arena)
666+
append_templatestr(PyUnicodeWriter *writer, expr_ty e)
668667
{
669668
int result = -1;
670-
671-
asdl_expr_seq *new_values = _Py_asdl_expr_seq_new(last_idx - first_idx + 1, arena);
672-
if (!new_values) {
673-
return result;
674-
}
675-
676-
Py_ssize_t j = 0;
677-
for (Py_ssize_t i = first_idx; i <= last_idx; ++i) {
678-
asdl_seq_SET(new_values, j++, asdl_seq_GET(values, i));
679-
}
680-
681-
PyObject *body = build_ftstring_body(new_values, false);
669+
PyObject *body = build_ftstring_body(e->v.TemplateStr.values, false);
682670
if (!body) {
683-
return result;
671+
return -1;
684672
}
685673

686-
if (-1 != append_char(writer, prefix) &&
674+
if (-1 != append_charp(writer, "t") &&
687675
-1 != append_repr(writer, body))
688676
{
689677
result = 0;
@@ -692,21 +680,6 @@ _write_values_subarray(PyUnicodeWriter *writer, asdl_expr_seq *values, Py_ssize_
692680
return result;
693681
}
694682

695-
static int
696-
append_templatestr(PyUnicodeWriter *writer, expr_ty e)
697-
{
698-
PyArena *arena = _PyArena_New();
699-
if (!arena) {
700-
return -1;
701-
}
702-
703-
Py_ssize_t len = asdl_seq_LEN(e->v.TemplateStr.values);
704-
int result = _write_values_subarray(writer, e->v.TemplateStr.values,
705-
0, len - 1, 't', arena);
706-
_PyArena_Free(arena);
707-
return result;
708-
}
709-
710683
static int
711684
append_joinedstr(PyUnicodeWriter *writer, expr_ty e, bool is_format_spec)
712685
{

0 commit comments

Comments
 (0)