[Python-checkins] cpython (merge default -> default): Merge

antoine.pitrou python-checkins at python.org
Fri Jul 15 21:21:07 CEST 2011


http://hg.python.org/cpython/rev/04feda56cab4
changeset: 71359:04feda56cab4
parent: 71353:7aaccab7a915
parent: 71357:0a040aa9bb34
user: Antoine Pitrou <solipsis at pitrou.net>
date: Fri Jul 15 21:19:27 2011 +0200
summary:
 Merge
files:
 Lib/test/test_descr.py | 8 ++++++++
 Misc/NEWS | 3 +++
 Objects/typeobject.c | 2 +-
 3 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4247,6 +4247,14 @@
 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):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -228,6 +228,9 @@
 Library
 -------
 
+- Issue #11603: Fix a crash when __str__ is rebound as __repr__. Patch by
+ Andreas Stührk.
+
 - Issue #11321: Fix a crash with multiple imports of the _pickle module when
 embedding Python. Patch by Andreas Stührk.
 
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -2968,7 +2968,7 @@
 unaryfunc f;
 
 f = Py_TYPE(self)->tp_repr;
- if (f == NULL)
+ if (f == NULL || f == object_str)
 f = object_repr;
 return f(self);
 }
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /