Skip to content
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

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

Open
wants to merge 8 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
Contributor

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
Contributor

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

Lib/test/test_inspect/test_inspect.py Outdated Show resolved Hide resolved
Lib/test/test_inspect/test_inspect.py Outdated Show resolved Hide resolved
Lib/test/test_inspect/test_inspect.py Outdated Show resolved Hide resolved
Lib/test/test_inspect/test_inspect.py Outdated Show resolved Hide resolved
Lib/test/test_inspect/test_inspect.py Outdated Show resolved Hide resolved
Doc/library/inspect.rst Outdated Show resolved Hide resolved
Doc/library/inspect.rst Outdated Show resolved Hide resolved
Lib/inspect.py Outdated Show resolved Hide resolved
Doc/library/inspect.rst Outdated Show resolved Hide resolved
@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
Contributor

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
Contributor

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

Doc/library/inspect.rst Outdated Show resolved Hide resolved
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
Contributor

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
Contributor

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

:attr:`!__doc__` attributes (properties, getsets and member descriptors have
them), but this is not guaranteed.

.. versionchanged:: 3.8
Copy link
Contributor

Choose a reason for hiding this comment

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

Was it really fixed since 3.8?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, with the PR gh-1959.

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

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