GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-82406: document duck-type nature of inspect.is*function by graingert · Pull Request #94987 · python/cpython

gh-82406: document duck-type nature of inspect.is*function #94987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
encukou merged 10 commits into python:main from graingert:document-duck-type-is-star-function
Sep 3, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

gh-82406: document duck-type nature of inspect.is*function #94987

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
10 commits
Select commit Hold shift + click to select a range
559200a
gh-82406: document duck-type nature of inspect.is*function
graingert Jul 18, 2022
864d46c
Update Doc/library/inspect.rst
graingert Jul 18, 2022
07d7a5f
comment document the implicit else branch
graingert Jul 18, 2022
3c3d198
📜🤖 Added by blurb_it.
blurb-it[bot] Jul 18, 2022
b3b5301
the inspect.is*function duck type change missed the boat for 3.10.5
graingert Jul 19, 2022
afe0483
Merge branch 'main' into document-duck-type-is-star-function
graingert Sep 2, 2026
666abb7
Apply batched suggestions from code review
graingert Sep 2, 2026
04325fa
fix lint
graingert Sep 2, 2026
a651bc9
Reword duck-type wording and finish the sentences
graingert Sep 2, 2026
2abecc3
Remove NEWS entry
encukou Sep 2, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

Some comments aren't visible on the classic Files Changed page.

There are no files selected for viewing

12 changes: 12 additions & 0 deletions 12 Doc/library/inspect.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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``.
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions 6 Lib/inspect.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -2338,7 +2340,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)
Expand Down Expand Up @@ -2531,7 +2533,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,
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.