Author miyakogi
Recipients gvanrossum, miyakogi, vstinner, yselivanov
Date 2016-01-18.12:54:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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)

>>> inspect.isgeneratorfunction(Mock(a))

With the patch, inspect.isgeneratorfunction(Mock(a)) returns True.
Date User Action Args
2016-01-18 12:54:47miyakogisetrecipients: + miyakogi, gvanrossum, vstinner, yselivanov
2016-01-18 12:54:47miyakogisetmessageid: <>
2016-01-18 12:54:46miyakogilinkissue26140 messages
2016-01-18 12:54:46miyakogicreate