diff options
author | Martijn Pieters <mj@zopatista.com> | 2024-02-15 11:08:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-15 11:08:45 (GMT) |
commit | edb59d57188e5535729c3948d673d0de1b729c05 (patch) | |
tree | 8de60290f8eda9ffc8dd5e060966218c7c5aed4e /Lib/functools.py | |
parent | 9e3729bbd77fb9dcaea6a06ac760160136d80b79 (diff) | |
download | cpython-edb59d57188e5535729c3948d673d0de1b729c05.zip cpython-edb59d57188e5535729c3948d673d0de1b729c05.tar.gz cpython-edb59d57188e5535729c3948d673d0de1b729c05.tar.bz2 |
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>
Diffstat (limited to 'Lib/functools.py')
-rw-r--r-- | Lib/functools.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Lib/functools.py b/Lib/functools.py index 55990e7..ee4197b 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -388,7 +388,7 @@ class partialmethod(object): keywords = {**self.keywords, **keywords} return self.func(cls_or_self, *self.args, *args, **keywords) _method.__isabstractmethod__ = self.__isabstractmethod__ - _method._partialmethod = self + _method.__partialmethod__ = self return _method def __get__(self, obj, cls=None): @@ -424,6 +424,17 @@ def _unwrap_partial(func): func = func.func return func +def _unwrap_partialmethod(func): + prev = None + while func is not prev: + prev = func + while isinstance(getattr(func, "__partialmethod__", None), partialmethod): + func = func.__partialmethod__ + while isinstance(func, partialmethod): + func = getattr(func, 'func') + func = _unwrap_partial(func) + return func + ################################################################################ ### LRU Cache function decorator ################################################################################ |