diff Objects/object.c @ 42184:bf5d04e0da4c

Make test_descr.py pass. Had to disable a few tests, remove references to 'file', and fix a bunch of subtleties in the behavior of objects related to overriding __str__. Also disabled a few tests that I couldn't see how to fix but that seemed to be checking silly stuff only.
author Guido van Rossum <guido@python.org>
date Wed, 11 Jul 2007 09:28:11 +0000
parents f83cc9b31a97
children a355359e47b4
line wrap: on
line diff
--- a/Objects/object.c	Wed Jul 11 06:56:16 2007 +0000
+++ b/Objects/object.c	Wed Jul 11 09:28:11 2007 +0000
@@ -415,9 +415,7 @@
 	res = (*v->ob_type->tp_str)(v);
 	if (res == NULL)
 		return NULL;
-	type_ok = PyString_Check(res);
-	type_ok = type_ok || PyUnicode_Check(res);
-	if (!type_ok) {
+	if (!(PyString_Check(res) || PyUnicode_Check(res))) {
 		PyErr_Format(PyExc_TypeError,
 			     "__str__ returned non-string (type %.200s)",
 			     res->ob_type->tp_name);
@@ -476,8 +474,10 @@
 	}
 	else {
 		PyErr_Clear();
-		if (PyUnicode_Check(v)) {
-			/* For a Unicode subtype that's didn't overwrite __unicode__,
+		if (PyUnicode_Check(v) &&
+		    v->ob_type->tp_str == PyUnicode_Type.tp_str) {
+			/* For a Unicode subtype that's didn't overwrite
+			   __unicode__ or __str__,
 			   return a true Unicode object with the same data. */
 			return PyUnicode_FromUnicode(PyUnicode_AS_UNICODE(v),
 			                             PyUnicode_GET_SIZE(v));