Title: Support functools.partial in*function() checks
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.8
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, pablogsal, yselivanov
Priority: normal Keywords: patch

Created on 2018-10-04 07:29 by asvetlov, last changed 2018-10-26 11:23 by pablogsal. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 9903 merged pablogsal, 2018-10-15 22:14
Messages (4)
msg327039 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2018-10-04 07:29
isfunction() processes both `isfunction(func)` and `isfunction(partial(func, arg))` correctly.

But `iscoroutinefunction()` misses this functionality.

We can implement it easy by adding a check for `isinstance(func, partial)` and applying a coroutine check for `func.func`.

Also, we can do the same for `isgeneratorfunction()` and `isasyncgenfunction()`.

The patch looks easy and straightforward.

Yuri, what do you think about?
msg327056 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-10-04 15:32
I think the fact that `inspect.isfunction` recognizes partials is a very strong argument to enable inspect.iscoroutinefunction to do so as well.  

This is a backwards incompatible change though, strictly speaking.
msg327057 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-10-04 15:33
Feel free to work on the PR.  If we want to push this to 3.8 we should do that now and have enough time for it to be tested.
msg328538 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2018-10-26 11:19
New changeset 7cd25434164882c2093ea41ccfc7b95a05cd5cbd by Pablo Galindo in branch 'master':
bpo-34890: Make iscoroutinefunction, isgeneratorfunction and isasyncgenfunction work with functools.partial (GH-9903)
Date User Action Args
2018-10-26 11:23:04pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-10-26 11:19:19pablogsalsetnosy: + pablogsal
messages: + msg328538
2018-10-15 22:14:22pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request9265
2018-10-04 15:33:50yselivanovsetmessages: + msg327057
2018-10-04 15:32:54yselivanovsetmessages: + msg327056
2018-10-04 07:29:56asvetlovcreate