Skip to content

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

zuo
Copy link
Contributor

@zuo zuo commented Jul 21, 2024

  • 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 zuo force-pushed the docs-and-tests-of-inspect-fixes-updates-improvements branch from ec0e2e9 to 5e7ce51 Compare July 21, 2024 23:32
@zuo zuo changed the title gb-122102: Fix/improve docs + tests of descriptor tools in inspect gh-122102: Fix/improve docs + tests of descriptor tools in inspect Jul 21, 2024
@zuo
Copy link
Contributor Author

zuo commented Jul 21, 2024

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

@picnixz
Copy link
Member

picnixz commented Jul 22, 2024

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.

Copy link
Member

@picnixz picnixz left a comment

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.

@zuo
Copy link
Contributor Author

zuo commented Jul 22, 2024

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
Copy link
Contributor Author

zuo commented Jul 22, 2024

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
Member

picnixz commented Jul 22, 2024

Does this rule apply also to documentation-only changes?

AFAIK, yes. @hugovk Do you confirm?

@zuo zuo force-pushed the docs-and-tests-of-inspect-fixes-updates-improvements branch from 8ee1d5a to 2a11629 Compare July 22, 2024 22:39
@zuo zuo changed the title gh-122102: Fix/improve docs + tests of descriptor tools in inspect gh-122102: Fix/improve docs of inspect.is{data,method}descriptor() Jul 22, 2024
@zuo zuo changed the title gh-122102: Fix/improve docs of inspect.is{data,method}descriptor() gh-122102: Fix/improve docs of descriptor-related tests in inspect Jul 22, 2024
@zuo zuo changed the title gh-122102: Fix/improve docs of descriptor-related tests in inspect gh-122102: Fix/improve docs of descriptor-related tools in inspect Jul 22, 2024
@zuo
Copy link
Contributor Author

zuo commented Jul 22, 2024

@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 picnixz July 22, 2024 23:26
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
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 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
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
Contributor Author

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 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
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
Contributor Author

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).

@zuo zuo requested a review from picnixz July 23, 2024 14:36
(further edits of docstrings)
@zuo
Copy link
Contributor Author

zuo commented Oct 2, 2024

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

Co-authored-by: Bénédikt Tran <[email protected]>
@zuo zuo requested a review from picnixz January 27, 2025 18:54
@picnixz
Copy link
Member

picnixz commented Feb 1, 2025

I will have a look at it when I'm back from traveling but I think we're mostly good now. I'm sorry I forgot about your PR..

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

Just English nits.

@@ -555,19 +555,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` are true.
Copy link
Member

Choose a reason for hiding this comment

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

Should we say "X, Y or Z is true" or "X, Y or Z are true"? @python/proofreaders

Comment on lines +566 to +569
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, e.g., count on
having the :attr:`~method.__func__` attribute when an object passes
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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, e.g., count on
having the :attr:`~method.__func__` attribute 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, e.g., count on
having the :attr:`~method.__func__` attribute when an object passes

To avoid linking twice in the same paragraph the functions.

Comment on lines +588 to +590
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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.
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.

Comment on lines +592 to +594
While data descriptors may have also :attr:`~definition.__name__` and
:attr:`!__doc__` attributes (as properties, getsets and member descriptors
do), this is not necessarily the case in general.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
While data descriptors may have also :attr:`~definition.__name__` and
:attr:`!__doc__` attributes (as properties, getsets and member descriptors
do), this is not necessarily the case in general.
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants