Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for infinite loop protection in inspect.unwrap()
  • Loading branch information
takluyver committed May 22, 2017
commit 2cb0a18450ef5e634123eb4539cc24961a1e02e7
18 changes: 18 additions & 0 deletions Lib/test/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3554,6 +3554,19 @@ def test_builtins_have_signatures(self):
self.assertIsNone(obj.__text_signature__)


class NTimesUnwrappable:
def __init__(self, n):
self.n = n
self._next = None

@property
def __wrapped__(self):
if self.n <= 0:
raise Exception("Unwrapped too many times")
if self._next is None:
self._next = NTimesUnwrappable(self.n - 1)
return self._next

class TestUnwrap(unittest.TestCase):

def test_unwrap_one(self):
Expand Down Expand Up @@ -3609,6 +3622,11 @@ class C:
__wrapped__ = func
self.assertIsNone(inspect.unwrap(C()))

def test_recursion_limit(self):
obj = NTimesUnwrappable(sys.getrecursionlimit() + 1)
with self.assertRaisesRegex(ValueError, 'wrapper loop'):
inspect.unwrap(obj)

class TestMain(unittest.TestCase):
def test_only_source(self):
module = importlib.import_module('unittest')
Expand Down