only catch AttributeError in hasattr() #9666

This commit is contained in:
Benjamin Peterson 2010-08-24 03:26:23 +00:00
parent 9cf5ef4cc0
commit 17689991e6
5 changed files with 19 additions and 17 deletions

View file

@ -495,15 +495,16 @@ class BuiltinTest(unittest.TestCase):
self.assertRaises(TypeError, hasattr)
self.assertEqual(False, hasattr(sys, chr(sys.maxunicode)))
# Check that hasattr allows SystemExit and KeyboardInterrupts by
# Check that hasattr propagates all exceptions outside of
# AttributeError.
class A:
def __getattr__(self, what):
raise KeyboardInterrupt
self.assertRaises(KeyboardInterrupt, hasattr, A(), "b")
raise SystemExit
self.assertRaises(SystemExit, hasattr, A(), "b")
class B:
def __getattr__(self, what):
raise SystemExit
self.assertRaises(SystemExit, hasattr, B(), "b")
raise ValueError
self.assertRaises(ValueError, hasattr, B(), "b")
def test_hash(self):
hash(None)