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.

classification
Title: Different behavior for functiools.partial between inspect.isfunction() and other inspect.is*function()
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: IliyaZinoviev, Kevin Shweh
Priority: normal Keywords:

Created on 2022-02-11 15:26 by IliyaZinoviev, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
isfuncs_behavior.py IliyaZinoviev, 2022-02-11 15:26
Messages (4)
msg413077 - (view) Author: Iliya Zinoviev (IliyaZinoviev) * Date: 2022-02-11 15:26
1) isfunction() returns `True` for partial object only when one passes `func` attribute of it.
2) For instance, `isgeneratorfunction()` and `iscoroutinefunction()` for partial obj work with passing partial obj as well as with passing `func` attr of this obj, when obj is partially applied generator function or partially applied coroutine function respectively.

I offer to unify behavior for handling partial object for r'inspect.is*function()' by the next way:
1) Add `functools._unwrap_partial()` to `inspect.isfunction()` as well as it were done in other r'inspect.is*function()'.

P.S.I'm ready to deal with this issue.  

Python 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0]
Type 'copyright', 'credits' or 'license' for more information

Operating System: Manjaro Linux
KDE Plasma Version: 5.23.5
KDE Frameworks Version: 5.90.0
Qt Version: 5.15.2
Kernel Version: 5.4.176-1-MANJARO (64-bit)
Graphics Platform: X11
Processors: 4 × Intel® Core™ i5-6200U CPU @ 2.30GHz
Memory: 11.6 GiB of RAM
Graphics Processor: Mesa Intel® HD Graphics 520
msg413111 - (view) Author: Kevin Shweh (Kevin Shweh) Date: 2022-02-12 00:35
Frankly, it doesn't make sense that isgeneratorfunction or iscoroutinefunction unwrap partials at all. The original justification for making them do that back in https://bugs.python.org/issue34890 was invalid - the original argument was that isfunction unwraps partials, but it doesn't, and I don't think it ever did.

isfunction is supposed to be a very specific check for Python function objects. It rejects all sorts of other callables, like sum (a built-in function), super (a type), or method objects (which wrap functions in a very similar way to partial). Having it be a check for *either* a Python function object *or* a partial object wrapping a Python function object seems to just make it less useful.
msg413127 - (view) Author: Iliya Zinoviev (IliyaZinoviev) * Date: 2022-02-12 12:47
Kevin, thanks for answer!

In that case, I may conclude isgeneratorfunction,
iscoroutinefunction, isasyncgenfunction from python3.7 are more determinated, in my view, cause partial obj has `func` attr for interaction with these funcs anyway, so it isn't need of an alternative.
msg413128 - (view) Author: Iliya Zinoviev (IliyaZinoviev) * Date: 2022-02-12 13:23
I suppose isgeneratorfunction,
iscoroutinefunction, isasyncgenfunction were modified to treat partial obj like regular function. But then without modifying isfunction as well, this approach won't work in full measure.
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 90878
2022-02-12 13:23:19IliyaZinovievsetmessages: + msg413128
2022-02-12 12:47:25IliyaZinovievsetmessages: + msg413127
2022-02-12 00:35:37Kevin Shwehsetnosy: + Kevin Shweh
messages: + msg413111
2022-02-11 16:24:32IliyaZinovievsetfiles: - isfuncs_behavior.py
2022-02-11 16:24:18IliyaZinovievsetfiles: + isfuncs_behavior.py
2022-02-11 15:26:49IliyaZinovievcreate