Limit the nesting depth of a tuple passed as the second argument to

isinstance() or issubclass() to the recursion limit of the interpreter.
This commit is contained in:
Brett Cannon 2004-03-20 22:52:14 +00:00
parent c69661725a
commit 4f65331483
3 changed files with 57 additions and 9 deletions

View file

@ -4,6 +4,7 @@
import unittest
from test import test_support
import sys
@ -244,7 +245,23 @@ class TestIsInstanceIsSubclass(unittest.TestCase):
self.assertEqual(True, issubclass(int, (long, (float, int))))
self.assertEqual(True, issubclass(str, (unicode, (Child, NewChild, basestring))))
def test_subclass_recursion_limit(self):
# make sure that issubclass raises RuntimeError before the C stack is
# blown
self.assertRaises(RuntimeError, blowstack, issubclass, str, str)
def test_isinstance_recursion_limit(self):
# make sure that issubclass raises RuntimeError before the C stack is
# blown
self.assertRaises(RuntimeError, blowstack, isinstance, '', str)
def blowstack(fxn, arg, compare_to):
# Make sure that calling isinstance with a deeply nested tuple for its
# argument will raise RuntimeError eventually.
tuple_arg = (compare_to,)
for cnt in xrange(sys.getrecursionlimit()+5):
tuple_arg = (tuple_arg,)
fxn(arg, tuple_arg)
def test_main():