]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Well darnit! The innocuous fix I made to PyObject_Print() caused
authorGuido van Rossum <guido@python.org>
Mon, 30 Apr 2001 14:39:18 +0000 (14:39 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 30 Apr 2001 14:39:18 +0000 (14:39 +0000)
printing of instances not to look for __str__().  Fix this.

Objects/classobject.c

index 80b7ae51f2973cb4a0a419cb0fac31cc169305d4..9f4d1555e99e806053c56f9efc52e7bfe518d4da 100644 (file)
@@ -781,6 +781,25 @@ instance_repr(PyInstanceObject *inst)
        return res;
 }
 
+static PyObject *
+instance_str(PyInstanceObject *inst)
+{
+       PyObject *func;
+       PyObject *res;
+       static PyObject *strstr;
+
+       if (strstr == NULL)
+               strstr = PyString_InternFromString("__str__");
+       func = instance_getattr(inst, strstr);
+       if (func == NULL) {
+               PyErr_Clear();
+               return instance_repr(inst);
+       }
+       res = PyEval_CallObject(func, (PyObject *)NULL);
+       Py_DECREF(func);
+       return res;
+}
+
 static long
 instance_hash(PyInstanceObject *inst)
 {
@@ -1827,7 +1846,7 @@ PyTypeObject PyInstance_Type = {
        &instance_as_mapping,                   /* tp_as_mapping */
        (hashfunc)instance_hash,                /* tp_hash */
        0,                                      /* tp_call */
-       0,                                      /* tp_str */
+       (reprfunc)instance_str,                 /* tp_str */
        (getattrofunc)instance_getattr,         /* tp_getattro */
        (setattrofunc)instance_setattr,         /* tp_setattro */
        0,                                      /* tp_as_buffer */