File tree Expand file tree Collapse file tree 3 files changed +12
-1
lines changed Expand file tree Collapse file tree 3 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -4252,6 +4252,14 @@ class FakeStr:
4252
4252
with self .assertRaises (TypeError ):
4253
4253
str .__add__ (fake_str , "abc" )
4254
4254
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 )
4255
4263
4256
4264
class DictProxyTests (unittest .TestCase ):
4257
4265
def setUp (self ):
Original file line number Diff line number Diff line change @@ -13,6 +13,9 @@ Core and Builtins
13
13
Library
14
14
-------
15
15
16
+ - Issue #11603: Fix a crash when __str__ is rebound as __repr__. Patch by
17
+ Andreas Stührk.
18
+
16
19
17
20
What's New in Python 3.1.4?
18
21
===========================
Original file line number Diff line number Diff line change @@ -2821,7 +2821,7 @@ object_str(PyObject *self)
2821
2821
unaryfunc f ;
2822
2822
2823
2823
f = Py_TYPE (self )-> tp_repr ;
2824
- if (f == NULL )
2824
+ if (f == NULL || f == object_str )
2825
2825
f = object_repr ;
2826
2826
return f (self );
2827
2827
}
You can’t perform that action at this time.
0 commit comments