From 17689991e6ef5831eae57b2e91f178256d6d3ccb Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Tue, 24 Aug 2010 03:26:23 +0000 Subject: only catch AttributeError in hasattr() #9666 --- Lib/test/test_builtin.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'Lib/test/test_builtin.py') diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index aef5de8a11..4e09ca5706 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -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) -- cgit v1.2.1