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 miyakogi
Recipients gvanrossum, miyakogi, vstinner, yselivanov
Date 2016-01-17.11:42:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1453030972.84.0.0646105171888.issue26140@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016-01-17 11:42:52miyakogisetrecipients: + miyakogi, gvanrossum, vstinner, yselivanov
2016-01-17 11:42:52miyakogisetmessageid: <1453030972.84.0.0646105171888.issue26140@psf.upfronthosting.co.za>
2016-01-17 11:42:52miyakogilinkissue26140 messages
2016-01-17 11:42:52miyakogicreate