https://github.com/python/cpython/commit/5646ec8c24ece01ebfa30ec6f06a5b67a43d5900 commit: 5646ec8c24ece01ebfa30ec6f06a5b67a43d5900 branch: 3.15 author: Miss Islington (bot) <[email protected]> committer: serhiy-storchaka <[email protected]> date: 2026-10-10T13:32:17+03:00 summary:
[3.15] gh-82406: Add 3.10.6 change notes for inspect.is*function (GH-94987) (GH-156882) Document when these functions started checking code flags for "duck-typed" function-like objects. (cherry picked from commit 1059e8072e24154bbcb9d4c881609821c117f6ab) Co-authored-by: Thomas Grainger <[email protected]> files: M Doc/library/inspect.rst M Lib/inspect.py diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index 07b0b005ceb3f5..dc096b743c6334 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -485,6 +485,10 @@ 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.10.6 + :term:`Duck-typed <duck-typing>` function-like objects now return + ``True`` if their code object has the :data:`CO_GENERATOR` flag. + .. versionchanged:: 3.13 Functions wrapped in :func:`functools.partialmethod` now return ``True`` if the wrapped function is a Python generator function. @@ -507,6 +511,10 @@ 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:`coroutine function`. + .. versionchanged:: 3.10.6 + :term:`Duck-typed <duck-typing>` function-like objects now return + ``True`` if their code object has the :data:`CO_COROUTINE` flag. + .. versionchanged:: 3.12 Sync functions marked with :func:`markcoroutinefunction` now return ``True``. @@ -581,6 +589,10 @@ attributes (see :ref:`import-mod-attrs` for module attributes): Functions wrapped in :func:`functools.partial` now return ``True`` if the wrapped function is an :term:`asynchronous generator` function. + .. versionchanged:: 3.10.6 + :term:`Duck-typed <duck-typing>` function-like objects now return + ``True`` if their code object has the :data:`CO_ASYNC_GENERATOR` flag. + .. versionchanged:: 3.13 Functions wrapped in :func:`functools.partialmethod` now return ``True`` if the wrapped function is a :term:`asynchronous generator` function. diff --git a/Lib/inspect.py b/Lib/inspect.py index e531ea40d26e48..dfaa5843a1fb87 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -298,6 +298,8 @@ def _has_code_flag(f, flag): f = functools._unwrap_partial(f) if not (isfunction(f) or _signature_is_functionlike(f)): return False + # If it's a pure Python function, or an object that is duck type + # of a Python function (Cython and Mock functions, for instance), then: return bool(f.__code__.co_flags & flag) def isgeneratorfunction(obj): @@ -2328,7 +2330,7 @@ def _signature_from_function(cls, func, skip_bound_arg=True, is_duck_function = True else: # If it's not a pure Python function, and not a duck type - # of pure function: + # of pure function (Cython and Mock functions, for instance), then: raise TypeError('{!r} is not a Python function'.format(func)) s = getattr(func, "__text_signature__", None) @@ -2521,7 +2523,7 @@ def _signature_from_callable(obj, *, if isfunction(obj) or _signature_is_functionlike(obj): # If it's a pure Python function, or an object that is duck type - # of a Python function (Cython functions, for instance), then: + # of a Python function (Cython and Mock functions, for instance), then: return _signature_from_function(sigcls, obj, skip_bound_arg=skip_bound_arg, globals=globals, locals=locals, eval_str=eval_str, _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
