diff -r 135a0d7bc4db Lib/test/test_class.py --- a/Lib/test/test_class.py Sun Mar 20 10:44:30 2011 +0800 +++ b/Lib/test/test_class.py Sun Mar 20 05:44:49 2011 +0100 @@ -545,6 +545,16 @@ a = A(hash(A.f)^(-1)) hash(a.f) + def testNoCrashIfStrIsRepr(self): + # See issue #11603 + class Foo: + pass + Foo.__repr__ = Foo.__str__ + + foo = Foo() + # The following line resulted in a crash or infinite loop + str(foo) + def test_main(): support.run_unittest(ClassTests) diff -r 135a0d7bc4db Objects/typeobject.c --- a/Objects/typeobject.c Sun Mar 20 10:44:30 2011 +0800 +++ b/Objects/typeobject.c Sun Mar 20 05:44:49 2011 +0100 @@ -2821,7 +2821,7 @@ unaryfunc f; f = Py_TYPE(self)->tp_repr; - if (f == NULL) + if (f == NULL || f == object_str) f = object_repr; return f(self); }