[issue26140] inspect.iscoroutinefunction raises TypeError when checks Mock of function or coroutinefunction
Hiroyuki Takagi
report at bugs.python.org
Mon Jan 18 07:54:47 EST 2016
Hiroyuki Takagi added the comment:
Thank you for review and comment.
Honestly speaking, I couldn't find any other good place to fix it.
One possible solution might be to use isinstance(mock, Mock) in iscoroutinefunction, but I don't think it's good for inspect module to add special check and depend on unittest.mock. Mocks are usually used only in debug/test, but iscoroutinefunction is used in production code. Adding some check to iscoroutinefunction only for test is not good for performance (though, actually its effect will be very small).
The reasons why I think this behavior should be fixed are,
- Raising error and stopping test is not kind for mock users
- After the patch (issue25599), no mock object can become `True` to iscoroutinefunction, which will make it impossible to test the block after if-iscoroutinefunction by using mock.
Now, I checked inspect module again, and found one more unexpected behavior (not error).
>>> def a(): yield 1
>>> inspect.isgeneratorfunction(a)
True
>>> inspect.isgeneratorfunction(Mock(a))
False
With the patch, inspect.isgeneratorfunction(Mock(a)) returns True.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26140>
_______________________________________
More information about the Python-bugs-list
mailing list