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 <[email protected]>
<http://bugs.python.org/issue26140>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com