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-18.12:54:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1453121687.01.0.180191013411.issue26140@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016-01-18 12:54:47miyakogisetrecipients: + miyakogi, gvanrossum, vstinner, yselivanov
2016-01-18 12:54:47miyakogisetmessageid: <1453121687.01.0.180191013411.issue26140@psf.upfronthosting.co.za>
2016-01-18 12:54:46miyakogilinkissue26140 messages
2016-01-18 12:54:46miyakogicreate