mirror of
https://github.com/python/cpython.git
synced 2025-11-25 12:44:13 +00:00
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:
parent
c69661725a
commit
4f65331483
3 changed files with 57 additions and 9 deletions
|
|
@ -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():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue