#1574217: only swallow AttributeErrors in isinstance, not everything.

Patch and tests by Brian Harring, with improvements by Ralf Schmitt.
This commit is contained in:
R. David Murray 2010-11-20 16:33:30 +00:00
parent f149e45a4e
commit 6bb9989ae3
4 changed files with 30 additions and 3 deletions

View file

@ -81,6 +81,20 @@ class TestIsInstanceExceptions(unittest.TestCase):
self.assertRaises(TypeError, isinstance, I(), C())
# check that we don't mask non AttributeErrors
# see: http://bugs.python.org/issue1574217
def test_isinstance_dont_mask_non_attribute_error(self):
class C(object):
def getclass(self):
raise RuntimeError()
__class__=property(getclass)
c=C()
self.assertRaises(RuntimeError, isinstance, c, bool)
# test another code path
class D: pass
self.assertRaises(RuntimeError, isinstance, c, D)
# These tests are similar to above, but tickle certain code paths in