Skip to content

Commit cb78792

Browse files
committed
gh-72088: clarify inspect.ismethod and isfunction usage with class-level access
Update inspect docs to note the behavioral differences between inspecting instance methods via the class versus via an instance when checking whether an object is a function or a method.
1 parent 6ef0f65 commit cb78792

1 file changed

Lines changed: 34 additions & 4 deletions

File tree

Doc/library/inspect.rst

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,12 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
425425

426426
Return ``True`` if the object is a bound method written in Python.
427427

428-
Note that accessing a method through the class (rather than an instance)
429-
returns a plain :term:`function`, not a bound method, so :func:`ismethod`
430-
will return ``False`` in that case. See :ref:`instance-methods` in the
431-
language reference for details.
428+
.. note::
429+
430+
Accessing an instance method through the class (rather than an instance)
431+
returns a plain :term:`function`, not a bound method, so :func:`ismethod`
432+
will return ``False`` in that case. See :ref:`instance-methods` in the
433+
language reference for details.
432434

433435

434436
.. function:: ispackage(object)
@@ -443,6 +445,13 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
443445
Return ``True`` if the object is a Python function, which includes functions
444446
created by a :term:`lambda` expression.
445447

448+
.. note::
449+
450+
Accessing an instance method through the class (rather than an instance)
451+
returns a plain :term:`function`, not a bound method, so :func:`isfunction`
452+
will return ``True`` in that case. See :ref:`instance-methods` in the
453+
language reference for details.
454+
446455

447456
.. function:: isgeneratorfunction(object)
448457

@@ -456,6 +465,13 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
456465
Functions wrapped in :func:`functools.partialmethod` now return ``True``
457466
if the wrapped function is a Python generator function.
458467

468+
.. note::
469+
470+
Accessing an instance method through the class (rather than an instance)
471+
returns a plain :term:`function`, not a bound method, so :func:`isgeneratorfunction`
472+
will return ``True`` in that case. See :ref:`instance-methods` in the
473+
language reference for details.
474+
459475
.. function:: isgenerator(object)
460476

461477
Return ``True`` if the object is a generator.
@@ -482,6 +498,13 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
482498
Functions wrapped in :func:`functools.partialmethod` now return ``True``
483499
if the wrapped function is a :term:`coroutine function`.
484500

501+
.. note::
502+
503+
Accessing an instance method through the class (rather than an instance)
504+
returns a plain :term:`function`, not a bound method, so :func:`iscoroutinefunction`
505+
will return ``True`` in that case. See :ref:`instance-methods` in the
506+
language reference for details.
507+
485508

486509
.. function:: markcoroutinefunction(func)
487510

@@ -552,6 +575,13 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
552575
Functions wrapped in :func:`functools.partialmethod` now return ``True``
553576
if the wrapped function is a :term:`asynchronous generator` function.
554577

578+
.. note::
579+
580+
Accessing an instance method through the class (rather than an instance)
581+
returns a plain :term:`function`, not a bound method, so :func:`isasyncgenfunction`
582+
will return ``True`` in that case. See :ref:`instance-methods` in the
583+
language reference for details.
584+
555585
.. function:: isasyncgen(object)
556586

557587
Return ``True`` if the object is an :term:`asynchronous generator iterator`

0 commit comments

Comments
 (0)