python / cpython

The Python programming language
https://www.python.org
Other
62.15k stars 29.86k forks source link

Need for a few corrections/updates regarding the `inspect.ismethoddescriptor()`'s and `inspect.isdatadescriptor()`'s docs and unit tests #122102

Open zuo opened 1 month ago

zuo commented 1 month ago

Documentation

  1. The main correction that needs to be made regards this fragment of the docs of inspect.ismethoddescriptor():

    Return True if the object is a method descriptor, but not if ismethod(), isclass(), isfunction() or isbuiltin() are true.

    The problem is that, in fact, the inspect.ismethoddescriptor() function does not engage the inspect.isbuiltin() function at all (whereas it does engage the rest of the said functions).

    (As it seems, the mistaken statement was introduced long ago...)

  2. Another thing worth fixing is the lack of the information that the inspect.isdatadescriptor() function also returns False if any of the ismethod(), isclass() or isfunction() tests are true.

  3. There are also a few other fragments of the docs of those two functions (inspect.ismethoddescriptor() and inspect.isdatadescriptor()) which seem to me worth updating/rewording...

  4. Naturally, it also seems a good idea to update the docstrings of those two functions (where applicable).

All those improvements have been proposed by submitting the first PR attached to this issue.

Tests

By the way, it seems worth to make the unit tests for those two functions be more comprehensive as well as consistent with each other.

The tests-related improvements have been proposed by submitting the second PR attached to this issue.

Linked PRs

zuo commented 1 month ago

See also:

(+ related PRs).

zuo commented 1 month ago

PS The documentation fixes/improvements seem worth applying to all supported Python versions: from 3.8 through 3.14.