Skip to content

Commit e3c7518

Browse files
[3.14] gh-82406: Add 3.10.6 change notes for inspect.is*function (GH-94987) (#156881)
Document when these functions started checking code flags for "duck-typed" function-like objects. (cherry picked from commit 1059e80) Co-authored-by: Thomas Grainger <tagrain@gmail.com>
1 parent 80f9604 commit e3c7518

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

Doc/library/inspect.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,10 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
468468
Functions wrapped in :func:`functools.partial` now return ``True`` if the
469469
wrapped function is a Python generator function.
470470

471+
.. versionchanged:: 3.10.6
472+
:term:`Duck-typed <duck-typing>` function-like objects now return
473+
``True`` if their code object has the :data:`CO_GENERATOR` flag.
474+
471475
.. versionchanged:: 3.13
472476
Functions wrapped in :func:`functools.partialmethod` now return ``True``
473477
if the wrapped function is a Python generator function.
@@ -490,6 +494,10 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
490494
Functions wrapped in :func:`functools.partial` now return ``True`` if the
491495
wrapped function is a :term:`coroutine function`.
492496

497+
.. versionchanged:: 3.10.6
498+
:term:`Duck-typed <duck-typing>` function-like objects now return
499+
``True`` if their code object has the :data:`CO_COROUTINE` flag.
500+
493501
.. versionchanged:: 3.12
494502
Sync functions marked with :func:`markcoroutinefunction` now return
495503
``True``.
@@ -564,6 +572,10 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
564572
Functions wrapped in :func:`functools.partial` now return ``True`` if the
565573
wrapped function is an :term:`asynchronous generator` function.
566574

575+
.. versionchanged:: 3.10.6
576+
:term:`Duck-typed <duck-typing>` function-like objects now return
577+
``True`` if their code object has the :data:`CO_ASYNC_GENERATOR` flag.
578+
567579
.. versionchanged:: 3.13
568580
Functions wrapped in :func:`functools.partialmethod` now return ``True``
569581
if the wrapped function is a :term:`asynchronous generator` function.

Lib/inspect.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ def _has_code_flag(f, flag):
298298
f = functools._unwrap_partial(f)
299299
if not (isfunction(f) or _signature_is_functionlike(f)):
300300
return False
301+
# If it's a pure Python function, or an object that is duck type
302+
# of a Python function (Cython and Mock functions, for instance), then:
301303
return bool(f.__code__.co_flags & flag)
302304

303305
def isgeneratorfunction(obj):
@@ -2320,7 +2322,7 @@ def _signature_from_function(cls, func, skip_bound_arg=True,
23202322
is_duck_function = True
23212323
else:
23222324
# If it's not a pure Python function, and not a duck type
2323-
# of pure function:
2325+
# of pure function (Cython and Mock functions, for instance), then:
23242326
raise TypeError('{!r} is not a Python function'.format(func))
23252327

23262328
s = getattr(func, "__text_signature__", None)
@@ -2513,7 +2515,7 @@ def _signature_from_callable(obj, *,
25132515

25142516
if isfunction(obj) or _signature_is_functionlike(obj):
25152517
# If it's a pure Python function, or an object that is duck type
2516-
# of a Python function (Cython functions, for instance), then:
2518+
# of a Python function (Cython and Mock functions, for instance), then:
25172519
return _signature_from_function(sigcls, obj,
25182520
skip_bound_arg=skip_bound_arg,
25192521
globals=globals, locals=locals, eval_str=eval_str,

0 commit comments

Comments
 (0)