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:
Martijn Pieters 2024-02-15 11:08:45 +00:00 committed by GitHub
parent 9e3729bbd7
commit edb59d5718
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 57 additions and 4 deletions

View file

@ -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: