New submission from Hiroyuki Takagi: inspect.iscoroutinefunction and asyncio.iscoroutinefunction with patch of issue25599 (https://bugs.python.org/issue25599) raise TypeError when used to check Mock object which mocks function or coroutinefunction.
How to reproduce: - For the mock of function >>> from unittest.mock import Mock >>> import inspect >>> def a():... ... >>> inspect.iscoroutinefunction(Mock(a)) Expected: False Actual: Traceback (most recent call last): File "<stdin>", line 1, in <module> File ".../cpython/Lib/inspect.py", line 187, in iscoroutinefunction object.__code__.co_flags & CO_COROUTINE) TypeError: unsupported operand type(s) for &: 'Mock' and 'int' - For the mock of coroutine-function >>> async def b():... ... >>> inspect.iscoroutinefunction(Mock(b)) Expected: True Actual: Traceback (most recent call last): File "<stdin>", line 1, in <module> File ".../cpython/Lib/inspect.py", line 187, in iscoroutinefunction object.__code__.co_flags & CO_COROUTINE) TypeError: unsupported operand type(s) for &: 'Mock' and 'int' Without the patch of issue25599, asyncio.iscoroutinefunction does not raise error and returns Mock object. But I don't think it is expected behavior, as discussed in that issue. I wrote a patch to solve this problem. ---------- components: asyncio files: mock.patch keywords: patch messages: 258464 nosy: gvanrossum, haypo, miyakogi, yselivanov priority: normal severity: normal status: open title: inspect.iscoroutinefunction raises TypeError when checks Mock of function or coroutinefunction type: behavior versions: Python 3.5 Added file: http://bugs.python.org/file41638/mock.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26140> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com