Skip to content

gh-122102: Fix/improve docs of descriptor-related tools in inspect - #122104

Merged
zware merged 16 commits into
python:mainfrom
zuo:docs-and-tests-of-inspect-fixes-updates-improvements
Jul 18, 2026
Merged

gh-122102: Fix/improve docs of descriptor-related tools in inspect#122104
zware merged 16 commits into
python:mainfrom
zuo:docs-and-tests-of-inspect-fixes-updates-improvements

Conversation

@zuo

@zuozuo commented Jul 21, 2024

Copy link
Copy Markdown
Contributor
  • Correct the docs of ismethoddescriptor() by removing the mistaken information about relation with isbuiltin().

  • Complement the docs of isdatadescriptor() by adding the missing information about relations with isclass(), ismethod() and isfunction().

  • Update and improve the docs (and docstrings) of those two functions.


📚 Documentation preview 📚: https://cpython-previews--122104.org.readthedocs.build/

@zuo
zuoforce-pushed the docs-and-tests-of-inspect-fixes-updates-improvements branch from ec0e2e9 to 5e7ce51CompareJuly 21, 2024 23:32
@zuozuo changed the title gb-122102: Fix/improve docs + tests of descriptor tools in inspectgh-122102: Fix/improve docs + tests of descriptor tools in inspectJul 21, 2024
@zuo

zuo commented Jul 21, 2024

Copy link
Copy Markdown
ContributorAuthor

Note: it may be worth to apply the documentation changes to all supported versions of Python (starting with 3.8).

@picnixz

picnixz commented Jul 22, 2024

Copy link
Copy Markdown
Member

Note: it may be worth to apply the documentation changes to all supported versions of Python (starting with 3.8)

  • 3.8 to 3.11 only accept security fixes
  • We can backport to 3.12 and 3.13.

@picnixzpicnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to emphasize the terms getset, you should do it for slot as well when talking about slot descriptors I think. Personally, I would simply consider getset as a common noun, so no need for having *getset* or *properties* as well.

Comment threadLib/test/test_inspect/test_inspect.py Outdated
Comment threadLib/test/test_inspect/test_inspect.py Outdated
Comment threadLib/test/test_inspect/test_inspect.py Outdated
Comment threadLib/test/test_inspect/test_inspect.py Outdated
Comment threadLib/test/test_inspect/test_inspect.py Outdated
Comment threadDoc/library/inspect.rst Outdated
Comment threadDoc/library/inspect.rst Outdated
Comment threadLib/inspect.py Outdated
Comment threadDoc/library/inspect.rst Outdated
@zuo

zuo commented Jul 22, 2024

Copy link
Copy Markdown
ContributorAuthor

Note: it may be worth to apply the documentation changes to all supported versions of Python (starting with 3.8)

* 3.8 to 3.11 only accept security fixes
* We can backport to 3.12 and 3.13.

Does this rule apply also to documentation-only changes?

@zuo

zuo commented Jul 22, 2024

Copy link
Copy Markdown
ContributorAuthor

If you want to emphasize the terms getset, you should do it for slot as well when talking about slot descriptors I think. Personally, I would simply consider getset as a common noun, so no need for having *getset* or *properties* as well.

OK, you convinced me. :)

@picnixz

Copy link
Copy Markdown
Member

Does this rule apply also to documentation-only changes?

AFAIK, yes. @hugovk Do you confirm?

@zuo
zuoforce-pushed the docs-and-tests-of-inspect-fixes-updates-improvements branch from 8ee1d5a to 2a11629CompareJuly 22, 2024 22:39
@zuozuo changed the title gh-122102: Fix/improve docs + tests of descriptor tools in inspectgh-122102: Fix/improve docs of inspect.is{data,method}descriptor()Jul 22, 2024
@zuozuo changed the title gh-122102: Fix/improve docs of inspect.is{data,method}descriptor()gh-122102: Fix/improve docs of descriptor-related tests in inspectJul 22, 2024
@zuozuo changed the title gh-122102: Fix/improve docs of descriptor-related tests in inspectgh-122102: Fix/improve docs of descriptor-related tools in inspectJul 22, 2024
@zuo

zuo commented Jul 22, 2024

Copy link
Copy Markdown
ContributorAuthor

@picnixz

I decided to exclude the tests-related changes from this PR, and create a separate PR that includes them.

Rationale: those two sets of changes may be desired to be backported to different sets of Python versions, as:

  • I believe that the unit-tests-related part should be backported (if at all) only to 3.13 – as those changes are, in fact, a continuation of the test improvements made as a part of inspect.ismethoddescriptor(): lack of __delete__() is not checked #120381
  • On the other hand, the docs-related part should, most probably, be backported not only to 3.13, but also to 3.12. (And maybe to some earlier versions as well? See a separate question, asked by me above...)

I am very sorry for the fuss with all this PR splitting (I should have thought about it earlier...). :-|

@zuo
zuo requested a review from picnixzJuly 22, 2024 23:26
Comment threadDoc/library/inspect.rst Outdated
Comment on lines +524 to +525
Method descriptors that also pass any of the other tests mentioned above
(:func:`isclass`, :func:`ismethod` or :func:`isfunction`) make this function

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit weird to say "mentioned above" and re-mention them. Either you mention them again (which I wouldn't suggest) or you just say "mentioned above".

Comment threadDoc/library/inspect.rst Outdated
Comment threadDoc/library/inspect.rst Outdated
Comment on lines +546 to +549
descriptors and member descriptors. Note that for the latter two (which can
be defined only at the C level, in extension modules) more specific tests
are available: :func:`isgetsetdescriptor` and :func:`ismemberdescriptor`,
respectively.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
descriptors and member descriptors. Note that for the latter two (which can
be defined only at the C level, in extension modules) more specific tests
are available: :func:`isgetsetdescriptor` and :func:`ismemberdescriptor`,
respectively.
descriptors and member descriptors. Note that specific tests robust
across different Python implementations are available for the latter
two (defined in C extension modules), namely :func:`isgetsetdescriptor`
and :func:`ismemberdescriptor` respectively.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the fragment about those two specific tests being robust across different Python implementations quite problematic: in a way, those two tests can be considered less robust across different Python implementations. (If I needed a test returning true for, e.g., a frame's f_locals regardless of the Python implementation being used, I'd use isdatadescriptor() rather than isgetsetdescriptor()...).

That's why I propose to remove that fragment.

IMHO, it causes more confusion than good.

Also I believe that the statement that those two tests are more specific, together with the docs of those two tests themselves, convey enough information.

Comment threadDoc/library/inspect.rst Outdated
Comment on lines +551 to +553
Typically, data descriptors have also :attr:`~definition.__name__` and
:attr:`!__doc__` attributes (properties, getsets and member descriptors have
them), but this is not guaranteed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Typically, data descriptors have also :attr:`~definition.__name__` and
:attr:`!__doc__` attributes (properties, getsets and member descriptors have
them), but this is not guaranteed.
While data descriptors such as properties, getsets or member descriptors
have :attr:`~definition.__name__` and :attr:`!__doc__` attributes, this
is not necessarily the case in general.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that the fragment referring to properties, getsets or member descriptors should remain in parentheses, as it conveys here only additional (extra) information, not the crucial one (which is that, in general, the presence of the data descriptors' attributes __name__ and __doc__ is likely but optional).

Comment threadDoc/library/inspect.rst
zuoand others added 3 commits July 23, 2024 15:50
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…2102.Za48MH.rst
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@zuo
zuo requested a review from picnixzJuly 23, 2024 14:36
(further edits of docstrings)
@zuo

zuo commented Oct 2, 2024

Copy link
Copy Markdown
ContributorAuthor

Sorry, I just learned that docs-only changes should not be announced in NEWS. So I delete the blurb.

Comment threadDoc/library/inspect.rst Outdated
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@read-the-docs-community

read-the-docs-communityBot commented Jul 18, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33645877 | 📁 Comparing d28b2b5 against main (ff56462)

🔍 Preview build

6 files changed · ± 6 modified

±Modified

zuoand others added 3 commits July 18, 2026 12:23
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Comment threadDoc/library/inspect.rst Outdated
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` are true.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be is true

Comment threadLib/inspect.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're probably due to update away from the "new in Python 2.2" note :)

Comment threadLib/inspect.py Outdated
the other tests promise more -- you can, e.g., count on having the
__func__ attribute (etc) when an object passes ismethod()."""
tests (ismethod(), isclass(), isfunction()) make this function return
false, simply because those other tests promise more -- you can, e.g.,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're generally moving away from latin abbreviations like e.g.; it can be expanded to "for example".

@zuo
zuo requested a review from zwareJuly 18, 2026 12:22
@zware
zware enabled auto-merge (squash) July 18, 2026 12:28
@zware

Copy link
Copy Markdown
Member

Thanks for the patch! This will merge after CI passes.

@zwarezware added sprint and removed stale Stale PR or inactive for long period of time. labels Jul 18, 2026
@github-project-automationgithub-project-automationBot moved this from Todo to In Progress in SprintJul 18, 2026
@zwarezware added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jul 18, 2026
@zware
zware merged commit 87f8fc8 into python:mainJul 18, 2026
61 checks passed
@github-project-automationgithub-project-automationBot moved this from In Progress to Done in SprintJul 18, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @zuo for the PR, and @zware for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

Copy link
Copy Markdown

GH-153948 is a backport of this pull request to the 3.15 branch.

@bedevere-appbedevere-appBot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 18, 2026
@bedevere-app

Copy link
Copy Markdown

GH-153949 is a backport of this pull request to the 3.14 branch.

@bedevere-appbedevere-appBot removed the needs backport to 3.14 bugs and security fixes label Jul 18, 2026
@bedevere-app

Copy link
Copy Markdown

GH-153950 is a backport of this pull request to the 3.13 branch.

@bedevere-appbedevere-appBot removed the needs backport to 3.13 bugs and security fixes label Jul 18, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants

@zuo@picnixz@zware