This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author stanislavlevin
Recipients stanislavlevin
Date 2020-10-06.07:12:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1601968342.61.0.658071347558.issue41954@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2020-10-06 07:12:22stanislavlevinsetrecipients: + stanislavlevin
2020-10-06 07:12:22stanislavlevinsetmessageid: <1601968342.61.0.658071347558.issue41954@roundup.psfhosted.org>
2020-10-06 07:12:22stanislavlevinlinkissue41954 messages
2020-10-06 07:12:22stanislavlevincreate