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

@ -340,6 +340,9 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
Functions wrapped in :func:`functools.partial` now return ``True`` if the
wrapped function is a Python generator function.
.. versionchanged:: 3.13
Functions wrapped in :func:`functools.partialmethod` now return ``True``
if the wrapped function is a Python generator function.
.. function:: isgenerator(object)
@ -363,6 +366,10 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
Sync functions marked with :func:`markcoroutinefunction` now return
``True``.
.. versionchanged:: 3.13
Functions wrapped in :func:`functools.partialmethod` now return ``True``
if the wrapped function is a :term:`coroutine function`.
.. function:: markcoroutinefunction(func)
@ -429,6 +436,9 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
Functions wrapped in :func:`functools.partial` now return ``True`` if the
wrapped function is a :term:`asynchronous generator` function.
.. versionchanged:: 3.13
Functions wrapped in :func:`functools.partialmethod` now return ``True``
if the wrapped function is a :term:`coroutine function`.
.. function:: isasyncgen(object)