Commits

Anonymous committed b488e02

Issue #11603: Fix a crash when __str__ is rebound as __repr__.
Patch by Andreas Stührk.

  • Participants
  • Parent commits 42ec507
  • Branches 3.1

Comments (0)

Files changed (3)

Lib/test/test_descr.py

         with self.assertRaises(TypeError):
             str.__add__(fake_str, "abc")
 
+    def test_repr_as_str(self):
+        # Issue #11603: crash or infinite loop when rebinding __str__ as
+        # __repr__.
+        class Foo:
+            pass
+        Foo.__repr__ = Foo.__str__
+        foo = Foo()
+        str(foo)
 
 class DictProxyTests(unittest.TestCase):
     def setUp(self):
 Library
 -------
 
+- Issue #11603: Fix a crash when __str__ is rebound as __repr__.  Patch by
+  Andreas Stührk.
+
 
 What's New in Python 3.1.4?
 ===========================

Objects/typeobject.c

     unaryfunc f;
 
     f = Py_TYPE(self)->tp_repr;
-    if (f == NULL)
+    if (f == NULL || f == object_str)
         f = object_repr;
     return f(self);
 }