changeset: 76519:0c1c8f8955d8 parent: 76517:507a6703d6a3 parent: 76518:971865f12377 user: Benjamin Peterson date: Tue Apr 24 11:09:20 2012 -0400 files: Lib/test/test_descr.py Misc/NEWS Objects/typeobject.c description: merge 3.2 (#14658) diff -r 507a6703d6a3 -r 0c1c8f8955d8 Lib/test/test_descr.py --- a/Lib/test/test_descr.py Tue Apr 24 10:32:57 2012 -0400 +++ b/Lib/test/test_descr.py Tue Apr 24 11:09:20 2012 -0400 @@ -4438,7 +4438,15 @@ pass Foo.__repr__ = Foo.__str__ foo = Foo() - str(foo) + self.assertRaises(RuntimeError, str, foo) + self.assertRaises(RuntimeError, repr, foo) + + def test_mixing_slot_wrappers(self): + class X(dict): + __setattr__ = dict.__setitem__ + x = X() + x.y = 42 + self.assertEqual(x["y"], 42) def test_slot_shadows_class_variable(self): with self.assertRaises(ValueError) as cm: diff -r 507a6703d6a3 -r 0c1c8f8955d8 Misc/NEWS --- a/Misc/NEWS Tue Apr 24 10:32:57 2012 -0400 +++ b/Misc/NEWS Tue Apr 24 11:09:20 2012 -0400 @@ -14,6 +14,12 @@ their keys with other dictionaries. Classes take advantage of this to share their instance dictionary keys for improved memory and performance. +- Issue #11603 (again): Setting __repr__ to __str__ now raises a RuntimeError + when repr() or str() is called on such an object. + +- Issue #14658: Fix binding a special method to a builtin implementation of a + special method with a different name. + - Issue #14630: Fix a memory access bug for instances of a subclass of int with value 0. diff -r 507a6703d6a3 -r 0c1c8f8955d8 Objects/typeobject.c --- a/Objects/typeobject.c Tue Apr 24 10:32:57 2012 -0400 +++ b/Objects/typeobject.c Tue Apr 24 11:09:20 2012 -0400 @@ -3035,7 +3035,7 @@ unaryfunc f; f = Py_TYPE(self)->tp_repr; - if (f == NULL || f == object_str) + if (f == NULL) f = object_repr; return f(self); } @@ -5879,7 +5879,8 @@ } continue; } - if (Py_TYPE(descr) == &PyWrapperDescr_Type) { + if (Py_TYPE(descr) == &PyWrapperDescr_Type && + ((PyWrapperDescrObject *)descr)->d_base->name_strobj == p->name_strobj) { void **tptr = resolve_slotdups(type, p->name_strobj); if (tptr == NULL || tptr == ptr) generic = p->function;

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