From: Guido van Rossum Date: Fri, 27 Apr 2001 21:35:01 +0000 (+0000) Subject: (Adding this to the trunk as well.) X-Git-Tag: v2.2a3~1949 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3a80c4a29c9eca9699b5bfe80541bc413a83bcef;p=thirdparty%2FPython%2Fcpython.git (Adding this to the trunk as well.) Fix a very old flaw in PyObject_Print(). Amazing! When an object type defines tp_str but not tp_repr, 'print x' to a real file object would not call the tp_str slot but rather print a default style representation: . This even though 'print x' to a file-like-object would correctly call the tp_str slot. --- diff --git a/Objects/object.c b/Objects/object.c index 47907bcb1d7f..1ace8f5b26c7 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -196,7 +196,10 @@ PyObject_Print(PyObject *op, FILE *fp, int flags) fprintf(fp, "", op->ob_refcnt, op); else if (op->ob_type->tp_print == NULL) { - if (op->ob_type->tp_repr == NULL) { + if ((flags & Py_PRINT_RAW) + ? (op->ob_type->tp_str == NULL) + : (op->ob_type->tp_repr == NULL)) + { fprintf(fp, "<%s object at %p>", op->ob_type->tp_name, op); }