diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-05-01 21:31:36 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-05-01 21:31:36 (GMT) |
commit | d9561318d849df12775d7a111aa85bbf62a54c0f (patch) | |
tree | 72c5bd9cfa4a614054c05a52cae6839a3679523c /Lib/test/test_descr.py | |
parent | da623ed9f43a13bc285a7e29ae8774d29c481332 (diff) | |
parent | 3249dec02484674830177488c8f01d8d04873928 (diff) | |
download | cpython-d9561318d849df12775d7a111aa85bbf62a54c0f.zip cpython-d9561318d849df12775d7a111aa85bbf62a54c0f.tar.gz cpython-d9561318d849df12775d7a111aa85bbf62a54c0f.tar.bz2 |
(Merge 3.1) Issue #9756: When calling a method descriptor or a slot wrapper
descriptor, the check of the object type doesn't read the __class__ attribute
anymore. Fix a crash if a class override its __class__ attribute (e.g. a proxy
of the str type).
Diffstat (limited to 'Lib/test/test_descr.py')
-rw-r--r-- | Lib/test/test_descr.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 41dfa70..6638116 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -4235,6 +4235,22 @@ order (MRO) for bases """ with self.assertRaises(AttributeError): del X.__abstractmethods__ + def test_proxy_call(self): + class FakeStr: + __class__ = str + + fake_str = FakeStr() + # isinstance() reads __class__ + self.assertTrue(isinstance(fake_str, str)) + + # call a method descriptor + with self.assertRaises(TypeError): + str.split(fake_str) + + # call a slot wrapper descriptor + with self.assertRaises(TypeError): + str.__add__(fake_str, "abc") + class DictProxyTests(unittest.TestCase): def setUp(self): |