summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_isinstance.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2004-03-20 22:52:14 (GMT)
committerBrett Cannon <bcannon@gmail.com>2004-03-20 22:52:14 (GMT)
commit4f65331483197a9909b19694688c55fdf9ca7a37 (patch)
tree1d8dae183e1f6528ca75c85082c4eeb8a4e8a803 /Lib/test/test_isinstance.py
parentc69661725a9d505d8f33a4a220d5489cb1de750f (diff)
downloadcpython-4f65331483197a9909b19694688c55fdf9ca7a37.zip
cpython-4f65331483197a9909b19694688c55fdf9ca7a37.tar.gz
cpython-4f65331483197a9909b19694688c55fdf9ca7a37.tar.bz2
Limit the nesting depth of a tuple passed as the second argument to
isinstance() or issubclass() to the recursion limit of the interpreter.
Diffstat (limited to 'Lib/test/test_isinstance.py')
-rw-r--r--Lib/test/test_isinstance.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/Lib/test/test_isinstance.py b/Lib/test/test_isinstance.py
index 1b8c593..4562114 100644
--- a/Lib/test/test_isinstance.py
+++ b/Lib/test/test_isinstance.py
@@ -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():