summaryrefslogtreecommitdiffstats
path: root/Modules/_collectionsmodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_collectionsmodule.c')
-rw-r--r--Modules/_collectionsmodule.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 493f314..4bcc1fd 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -1209,16 +1209,32 @@ static PyObject *
defdict_repr(defdictobject *dd)
{
PyObject *baserepr;
- PyObject *def;
+ PyObject *defrepr;
PyObject *result;
baserepr = PyDict_Type.tp_repr((PyObject *)dd);
if (baserepr == NULL)
return NULL;
if (dd->default_factory == NULL)
- def = Py_None;
+ defrepr = PyUnicode_FromString("None");
else
- def = dd->default_factory;
- result = PyUnicode_FromFormat("defaultdict(%R, %U)", def, baserepr);
+ {
+ int status = Py_ReprEnter(dd->default_factory);
+ if (status != 0) {
+ if (status < 0)
+ return NULL;
+ defrepr = PyUnicode_FromString("...");
+ }
+ else
+ defrepr = PyObject_Repr(dd->default_factory);
+ Py_ReprLeave(dd->default_factory);
+ }
+ if (defrepr == NULL) {
+ Py_DECREF(baserepr);
+ return NULL;
+ }
+ result = PyUnicode_FromFormat("defaultdict(%U, %U)",
+ defrepr, baserepr);
+ Py_DECREF(defrepr);
Py_DECREF(baserepr);
return result;
}