mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
(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).
This commit is contained in:
commit
d9561318d8
3 changed files with 27 additions and 3 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue