File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4252,6 +4252,14 @@ class FakeStr:
42524252 with self .assertRaises (TypeError ):
42534253 str .__add__ (fake_str , "abc" )
42544254
4255+ def test_repr_as_str (self ):
4256+ # Issue #11603: crash or infinite loop when rebinding __str__ as
4257+ # __repr__.
4258+ class Foo :
4259+ pass
4260+ Foo .__repr__ = Foo .__str__
4261+ foo = Foo ()
4262+ str (foo )
42554263
42564264class DictProxyTests (unittest .TestCase ):
42574265 def setUp (self ):
Original file line number Diff line number Diff line change @@ -27,6 +27,9 @@ Core and Builtins
2727Library
2828-------
2929
30+ - Issue #11603: Fix a crash when __str__ is rebound as __repr__. Patch by
31+ Andreas Stührk.
32+
3033- Issue #11321: Fix a crash with multiple imports of the _pickle module when
3134 embedding Python. Patch by Andreas Stührk.
3235
Original file line number Diff line number Diff line change @@ -2890,7 +2890,7 @@ object_str(PyObject *self)
28902890 unaryfunc f ;
28912891
28922892 f = Py_TYPE (self )-> tp_repr ;
2893- if (f == NULL )
2893+ if (f == NULL || f == object_str )
28942894 f = object_repr ;
28952895 return f (self );
28962896}
You can’t perform that action at this time.
0 commit comments