diff options
author | Guido van Rossum <guido@python.org> | 2001-04-30 14:39:18 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-04-30 14:39:18 (GMT) |
commit | 82c690f11ac93f5a3055f614ddd7f1cd29793136 (patch) | |
tree | 3cce5dfc79bfeeb00f2d174b2bbb7bb812b1720e /Objects/classobject.c | |
parent | cab3f68f612a7f088bed4005b335078a913b7b0f (diff) | |
download | cpython-82c690f11ac93f5a3055f614ddd7f1cd29793136.zip cpython-82c690f11ac93f5a3055f614ddd7f1cd29793136.tar.gz cpython-82c690f11ac93f5a3055f614ddd7f1cd29793136.tar.bz2 |
Well darnit! The innocuous fix I made to PyObject_Print() caused
printing of instances not to look for __str__(). Fix this.
Diffstat (limited to 'Objects/classobject.c')
-rw-r--r-- | Objects/classobject.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c index 80b7ae5..9f4d155 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -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 */ |