Message258464
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. |
|
Date |
User |
Action |
Args |
2016-01-17 11:42:52 | miyakogi | set | recipients:
+ miyakogi, gvanrossum, vstinner, yselivanov |
2016-01-17 11:42:52 | miyakogi | set | messageid: <1453030972.84.0.0646105171888.issue26140@psf.upfronthosting.co.za> |
2016-01-17 11:42:52 | miyakogi | link | issue26140 messages |
2016-01-17 11:42:52 | miyakogi | create | |
|