New submission from Stanislav Levin <s...@altlinux.org>:
With Python 3.8 the mocking of `inspect.isfunction` results in recursion. Please, consider a code snippet: ```python from unittest import TestCase from unittest.mock import patch import inspect class TestClass(TestCase): def setUp(self): patcher = patch('inspect.isfunction') self.addCleanup(patcher.stop) self.patched_func = patcher.start() def test_m(self): def f(): pass inspect.isfunction(f) ``` Output: ``` ERROR: test_m (test.TestClass) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/src/test.py", line 16, in test_m inspect.isfunction(f) File "/usr/lib64/python3.8/unittest/mock.py", line 1081, in __call__ return self._mock_call(*args, **kwargs) File "/usr/lib64/python3.8/unittest/mock.py", line 1085, in _mock_call return self._execute_mock_call(*args, **kwargs) File "/usr/lib64/python3.8/unittest/mock.py", line 1157, in _execute_mock_call return self.return_value File "/usr/lib64/python3.8/unittest/mock.py", line 526, in __get_return_value ret = self._get_child_mock( File "/usr/lib64/python3.8/unittest/mock.py", line 1025, in _get_child_mock return klass(**kw) File "/usr/lib64/python3.8/unittest/mock.py", line 408, in __new__ sig = inspect.signature(NonCallableMock.__init__) File "/usr/lib64/python3.8/inspect.py", line 3093, in signature return Signature.from_callable(obj, follow_wrapped=follow_wrapped) File "/usr/lib64/python3.8/inspect.py", line 2842, in from_callable return _signature_from_callable(obj, sigcls=cls, File "/usr/lib64/python3.8/inspect.py", line 2289, in _signature_from_callable if isfunction(obj) or _signature_is_functionlike(obj): File "/usr/lib64/python3.8/unittest/mock.py", line 1081, in __call__ return self._mock_call(*args, **kwargs) File "/usr/lib64/python3.8/unittest/mock.py", line 1085, in _mock_call return self._execute_mock_call(*args, **kwargs) File "/usr/lib64/python3.8/unittest/mock.py", line 1157, in _execute_mock_call return self.return_value File "/usr/lib64/python3.8/unittest/mock.py", line 526, in __get_return_value ret = self._get_child_mock( File "/usr/lib64/python3.8/unittest/mock.py", line 1025, in _get_child_mock return klass(**kw) ... return _signature_from_callable(obj, sigcls=cls, RecursionError: maximum recursion depth exceeded ``` breaking commit: https://github.com/python/cpython/commit/77b3b7701a34ecf6316469e05b79bb91de2addfa The pre-77b3b7701a34ecf6316469e05b79bb91de2addfa state of `Lib/unittest/mock.py` works as expected. ---------- messages: 378094 nosy: stanislavlevin priority: normal severity: normal status: open title: [mock] Recursion on mocking inspect.isfunction type: behavior versions: Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue41954> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com