diff options
author | Benjamin Peterson <benjamin@python.org> | 2010-08-24 03:26:23 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2010-08-24 03:26:23 (GMT) |
commit | 17689991e6ef5831eae57b2e91f178256d6d3ccb (patch) | |
tree | 21a954c86d8f461ecc06d8c6de8880429c6e97ec /Lib | |
parent | 9cf5ef4cc0015848ef831db31b19c77e6a4273e0 (diff) | |
download | cpython-17689991e6ef5831eae57b2e91f178256d6d3ccb.zip cpython-17689991e6ef5831eae57b2e91f178256d6d3ccb.tar.gz cpython-17689991e6ef5831eae57b2e91f178256d6d3ccb.tar.bz2 |
only catch AttributeError in hasattr() #9666
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_builtin.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index aef5de8..4e09ca5 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) |