mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
only catch AttributeError in hasattr() #9666
This commit is contained in:
parent
9cf5ef4cc0
commit
17689991e6
5 changed files with 19 additions and 17 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue