summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_descr.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-11-17 22:45:50 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-11-17 22:45:50 (GMT)
commit9262b849fba5cb6930a59114cdd6f95ad2847abb (patch)
treeed344f20374c141944dea26d6082a118bca5a7ca /Lib/test/test_descr.py
parentce0506ced3f04e751eb841111b43ce9c29fcdd07 (diff)
downloadcpython-9262b849fba5cb6930a59114cdd6f95ad2847abb.zip
cpython-9262b849fba5cb6930a59114cdd6f95ad2847abb.tar.gz
cpython-9262b849fba5cb6930a59114cdd6f95ad2847abb.tar.bz2
Merged revisions 67246 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r67246 | benjamin.peterson | 2008-11-17 16:39:09 -0600 (Mon, 17 Nov 2008) | 5 lines when __getattr__ is a descriptor, call it correctly; fixes #4230 patch from Ziga Seilnacht ........
Diffstat (limited to 'Lib/test/test_descr.py')
-rw-r--r--Lib/test/test_descr.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 735c9f0..fa3e0c3 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4001,6 +4001,46 @@ order (MRO) for bases """
c[1:2] = 3
self.assertEqual(c.value, 3)
+ def test_getattr_hooks(self):
+ # issue 4230
+
+ class Descriptor(object):
+ counter = 0
+ def __get__(self, obj, objtype=None):
+ def getter(name):
+ self.counter += 1
+ raise AttributeError(name)
+ return getter
+
+ descr = Descriptor()
+ class A(object):
+ __getattribute__ = descr
+ class B(object):
+ __getattr__ = descr
+ class C(object):
+ __getattribute__ = descr
+ __getattr__ = descr
+
+ self.assertRaises(AttributeError, getattr, A(), "attr")
+ self.assertEquals(descr.counter, 1)
+ self.assertRaises(AttributeError, getattr, B(), "attr")
+ self.assertEquals(descr.counter, 2)
+ self.assertRaises(AttributeError, getattr, C(), "attr")
+ self.assertEquals(descr.counter, 4)
+
+ import gc
+ class EvilGetattribute(object):
+ # This used to segfault
+ def __getattr__(self, name):
+ raise AttributeError(name)
+ def __getattribute__(self, name):
+ del EvilGetattribute.__getattr__
+ for i in range(5):
+ gc.collect()
+ raise AttributeError(name)
+
+ self.assertRaises(AttributeError, getattr, EvilGetattribute(), "attr")
+
class DictProxyTests(unittest.TestCase):
def setUp(self):