mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
bpo-38364: unwrap partialmethods just like we unwrap partials (#16600)
* bpo-38364: unwrap partialmethods just like we unwrap partials The inspect.isgeneratorfunction, inspect.iscoroutinefunction and inspect.isasyncgenfunction already unwrap functools.partial objects, this patch adds support for partialmethod objects as well. Also: Rename _partialmethod to __partialmethod__. Since we're checking this attribute on arbitrary function-like objects, we should use the namespace reserved for core Python. --------- Co-authored-by: Petr Viktorin <encukou@gmail.com>
This commit is contained in:
parent
9e3729bbd7
commit
edb59d5718
5 changed files with 57 additions and 4 deletions
|
@ -383,8 +383,10 @@ def isfunction(object):
|
|||
|
||||
def _has_code_flag(f, flag):
|
||||
"""Return true if ``f`` is a function (or a method or functools.partial
|
||||
wrapper wrapping a function) whose code object has the given ``flag``
|
||||
wrapper wrapping a function or a functools.partialmethod wrapping a
|
||||
function) whose code object has the given ``flag``
|
||||
set in its flags."""
|
||||
f = functools._unwrap_partialmethod(f)
|
||||
while ismethod(f):
|
||||
f = f.__func__
|
||||
f = functools._unwrap_partial(f)
|
||||
|
@ -2561,7 +2563,7 @@ def _signature_from_callable(obj, *,
|
|||
return sig
|
||||
|
||||
try:
|
||||
partialmethod = obj._partialmethod
|
||||
partialmethod = obj.__partialmethod__
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue