From: Benjamin Peterson Date: Tue, 24 Apr 2012 15:09:20 +0000 (-0400) Subject: merge 3.2 (#14658) X-Git-Tag: v3.3.0a3~96 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=42f58818d6100c2bef07245e360e7d8ca660058f;p=python merge 3.2 (#14658) --- 42f58818d6100c2bef07245e360e7d8ca660058f diff --cc Lib/test/test_descr.py index c0c741407d,2289f6e577..b9b1c7275f --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@@ -4438,56 -4430,16 +4438,64 @@@ order (MRO) for bases "" 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: + class X: + __slots__ = ["foo"] + foo = None + m = str(cm.exception) + self.assertEqual("'foo' in __slots__ conflicts with class variable", m) + + def test_set_doc(self): + class X: + "elephant" + X.__doc__ = "banana" + self.assertEqual(X.__doc__, "banana") + with self.assertRaises(TypeError) as cm: + type(list).__dict__["__doc__"].__set__(list, "blah") + self.assertIn("can't set list.__doc__", str(cm.exception)) + with self.assertRaises(TypeError) as cm: + type(X).__dict__["__doc__"].__delete__(X) + self.assertIn("can't delete X.__doc__", str(cm.exception)) + self.assertEqual(X.__doc__, "banana") + + def test_qualname(self): + descriptors = [str.lower, complex.real, float.real, int.__add__] + types = ['method', 'member', 'getset', 'wrapper'] + + # make sure we have an example of each type of descriptor + for d, n in zip(descriptors, types): + self.assertEqual(type(d).__name__, n + '_descriptor') + + for d in descriptors: + qualname = d.__objclass__.__qualname__ + '.' + d.__name__ + self.assertEqual(d.__qualname__, qualname) + + self.assertEqual(str.lower.__qualname__, 'str.lower') + self.assertEqual(complex.real.__qualname__, 'complex.real') + self.assertEqual(float.real.__qualname__, 'float.real') + self.assertEqual(int.__add__.__qualname__, 'int.__add__') + + def test_qualname_dict(self): + ns = {'__qualname__': 'some.name'} + tp = type('Foo', (), ns) + self.assertEqual(tp.__qualname__, 'some.name') + self.assertEqual(tp.__dict__['__qualname__'], 'some.name') + self.assertEqual(ns, {'__qualname__': 'some.name'}) + + ns = {'__qualname__': 1} + self.assertRaises(TypeError, type, 'Foo', (), ns) + def test_cycle_through_dict(self): # See bug #1469629 class X(dict): diff --cc Misc/NEWS index 2b7b8adbe3,2d58cb618e..b6b76ff16a --- a/Misc/NEWS +++ b/Misc/NEWS @@@ -10,10 -10,12 +10,16 @@@ What's New in Python 3.3.0 Alpha 3 Core and Builtins ----------------- +- Issue #13903: Implement PEP 412. Individual dictionary instances can now share + 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.