Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-122102: Fix/improve docs of descriptor-related tools in inspect#122104
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.
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
zware
merged 16 commits into
python:main
from
zuo:docs-and-tests-of-inspect-fixes-updates-improvementsJul 18, 2026
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2a11629
gh-122102: Fix/improve docs of `inspect.is{data,method}descriptor()`
zuo e0ba39d
gh-122102: Fix/improve docstrings of `inspect.is{data,method}descript…
zuo b59b533
Update Doc/library/inspect.rst
zuo 8aa2934
Update Misc/NEWS.d/next/Documentation/2024-07-22-01-30-49.gh-issue-12…
zuo f8ad14d
Update Doc/library/inspect.rst
zuo 53077a8
Update Lib/inspect.py
zuo db0bd35
Delete the blurb (unneeded to docs-only changes)
zuo 31fdce2
Merge branch 'main' into docs-and-tests-of-inspect-fixes-updates-impr…
zuo 5351773
Update Doc/library/inspect.rst
zuo cb2e360
Merge branch 'main' into docs-and-tests-of-inspect-fixes-updates-impr…
zuo 38cf81a
Merge branch 'python:main' into docs-and-tests-of-inspect-fixes-updat…
zuo abd2552
Apply suggestion from @picnixz - remove redundant links
zuo 99da393
Apply suggestion from @picnixz (add comma)
zuo 521c83b
Apply suggestion from @picnixz (tiny grammar fix)
zuo 24ee2af
A few more edits (CR)
zuo d28b2b5
Merge branch 'main' into docs-and-tests-of-inspect-fixes-updates-impr…
zuo File filter
Filter by extension
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
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -635,19 +635,18 @@ attributes (see :ref:`import-mod-attrs` for module attributes): | ||
| .. function:: ismethoddescriptor(object) | ||
| Return ``True`` if the object is a method descriptor, but not if | ||
| :func:`ismethod`, :func:`isclass`, :func:`isfunction` or :func:`isbuiltin` | ||
| are true. | ||
| :func:`isclass`, :func:`ismethod` or :func:`isfunction` is true. | ||
| This, for example, is true of ``int.__add__``. An object passing this test | ||
| has a :meth:`~object.__get__` method, but not a :meth:`~object.__set__` | ||
| method or a :meth:`~object.__delete__` method. Beyond that, the set of | ||
| attributes varies. A :attr:`~definition.__name__` attribute is usually | ||
| sensible, and :attr:`~definition.__doc__` often is. | ||
| Methods implemented via descriptors that also pass one of the other tests | ||
| return ``False`` from the :func:`ismethoddescriptor` test, simply because the | ||
| other tests promise more -- you can, e.g., count on having the | ||
| :attr:`~method.__func__` attribute (etc) when an object passes | ||
| Method descriptors that also pass any of the other tests (:func:`!isclass`, | ||
| :func:`!ismethod` or :func:`!isfunction`) make this function return ``False``, | ||
| simply because those other tests promise more -- you can, for example, count | ||
| on having the :attr:`~method.__func__` attribute when an object passes | ||
| :func:`ismethod`. | ||
| .. versionchanged:: 3.13 | ||
| @@ -658,16 +657,28 @@ attributes (see :ref:`import-mod-attrs` for module attributes): | ||
| .. function:: isdatadescriptor(object) | ||
| Return ``True`` if the object is a data descriptor. | ||
| Return ``True`` if the object is a data descriptor, but not if | ||
| :func:`isclass`, :func:`ismethod` or :func:`isfunction` is true. | ||
| Data descriptors have a :attr:`~object.__set__` or a :attr:`~object.__delete__` method. | ||
| Examples are properties (defined in Python), getsets, and members. The | ||
| latter two are defined in C and there are more specific tests available for | ||
| those types, which is robust across Python implementations. Typically, data | ||
| descriptors will also have :attr:`~definition.__name__` and :attr:`!__doc__` attributes | ||
| (properties, getsets, and members have both of these attributes), but this is | ||
| not guaranteed. | ||
| Data descriptors always have a :meth:`~object.__set__` method and/or | ||
| a :meth:`~object.__delete__` method. Optionally, they may also have a | ||
| :meth:`~object.__get__` method. | ||
| Examples of data descriptors are :func:`properties <property>`, getsets and | ||
| member descriptors. Note that for the latter two (defined only in C extension | ||
| modules), more specific tests are available: :func:`isgetsetdescriptor` and | ||
| :func:`ismemberdescriptor`, respectively. | ||
| While data descriptors may also have :attr:`~definition.__name__` and | ||
| :attr:`!__doc__` attributes (as properties, getsets and member descriptors | ||
| do), this is not necessarily the case in general. | ||
| .. versionchanged:: 3.8 | ||
picnixz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| This function now reports objects with only a :meth:`~object.__set__` method | ||
| as being data descriptors (the presence of :meth:`~object.__get__` is no | ||
| longer required for that). Moreover, objects with :meth:`~object.__delete__`, | ||
| but not :meth:`~object.__set__`, are now properly recognized as data | ||
| descriptors as well, which was not the case previously. | ||
| .. function:: isgetsetdescriptor(object) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Uh oh!
There was an error while loading. Please reload this page.