Skip to content

Commit 16f8ca3

Browse files
committed
Don't hardcode the class name in case of a cycle.
Pass the original `op` to `Py_ReprEnter`/`Py_ReprLeave` to avoid compiler warnings.
1 parent 654ff70 commit 16f8ca3

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

Objects/templateobject.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,12 @@ template_repr(PyObject *op)
213213
{
214214
templateobject *self = templateobject_CAST(op);
215215

216-
int res = Py_ReprEnter(self);
216+
int res = Py_ReprEnter(op);
217217
if (res != 0) {
218-
return (res > 0 ? PyUnicode_FromString("Template(...)") : NULL);
218+
if (res < 0)
219+
return NULL;
220+
else
221+
return PyUnicode_FromFormat("%s(...)", _PyType_Name(Py_TYPE(self)));
219222
}
220223

221224
Py_ssize_t stringslen = PyTuple_GET_SIZE(self->strings);
@@ -268,12 +271,12 @@ template_repr(PyObject *op)
268271
goto error;
269272
}
270273

271-
Py_ReprLeave(self);
274+
Py_ReprLeave(op);
272275

273276
return PyUnicodeWriter_Finish(writer);
274277

275278
error:
276-
Py_ReprLeave(self);
279+
Py_ReprLeave(op);
277280
PyUnicodeWriter_Discard(writer);
278281
return NULL;
279282
}

0 commit comments

Comments
 (0)