Skip to content

Commit 2f6fb5f

Browse files
[3.13] gh-82406: Add 3.10.6 change notes for inspect.is*function (GH-94987) (#156880)
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 251d82e commit 2f6fb5f

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
@@ -388,6 +388,10 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
388388
Functions wrapped in :func:`functools.partial` now return ``True`` if the
389389
wrapped function is a Python generator function.
390390

391+
.. versionchanged:: 3.10.6
392+
:term:`Duck-typed <duck-typing>` function-like objects now return
393+
``True`` if their code object has the :data:`CO_GENERATOR` flag.
394+
391395
.. versionchanged:: 3.13
392396
Functions wrapped in :func:`functools.partialmethod` now return ``True``
393397
if the wrapped function is a Python generator function.
@@ -410,6 +414,10 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
410414
Functions wrapped in :func:`functools.partial` now return ``True`` if the
411415
wrapped function is a :term:`coroutine function`.
412416

417+
.. versionchanged:: 3.10.6
418+
:term:`Duck-typed <duck-typing>` function-like objects now return
419+
``True`` if their code object has the :data:`CO_COROUTINE` flag.
420+
413421
.. versionchanged:: 3.12
414422
Sync functions marked with :func:`markcoroutinefunction` now return
415423
``True``.
@@ -484,6 +492,10 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
484492
Functions wrapped in :func:`functools.partial` now return ``True`` if the
485493
wrapped function is an :term:`asynchronous generator` function.
486494

495+
.. versionchanged:: 3.10.6
496+
:term:`Duck-typed <duck-typing>` function-like objects now return
497+
``True`` if their code object has the :data:`CO_ASYNC_GENERATOR` flag.
498+
487499
.. versionchanged:: 3.13
488500
Functions wrapped in :func:`functools.partialmethod` now return ``True``
489501
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
@@ -414,6 +414,8 @@ def _has_code_flag(f, flag):
414414
f = functools._unwrap_partial(f)
415415
if not (isfunction(f) or _signature_is_functionlike(f)):
416416
return False
417+
# If it's a pure Python function, or an object that is duck type
418+
# of a Python function (Cython and Mock functions, for instance), then:
417419
return bool(f.__code__.co_flags & flag)
418420

419421
def isgeneratorfunction(obj):
@@ -2408,7 +2410,7 @@ def _signature_from_function(cls, func, skip_bound_arg=True,
24082410
is_duck_function = True
24092411
else:
24102412
# If it's not a pure Python function, and not a duck type
2411-
# of pure function:
2413+
# of pure function (Cython and Mock functions, for instance), then:
24122414
raise TypeError('{!r} is not a Python function'.format(func))
24132415

24142416
s = getattr(func, "__text_signature__", None)
@@ -2601,7 +2603,7 @@ def _signature_from_callable(obj, *,
26012603

26022604
if isfunction(obj) or _signature_is_functionlike(obj):
26032605
# If it's a pure Python function, or an object that is duck type
2604-
# of a Python function (Cython functions, for instance), then:
2606+
# of a Python function (Cython and Mock functions, for instance), then:
26052607
return _signature_from_function(sigcls, obj,
26062608
skip_bound_arg=skip_bound_arg,
26072609
globals=globals, locals=locals, eval_str=eval_str)

0 commit comments

Comments
 (0)