-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
gh-140160: Doc improve PyObject_IsSubclass documentation for clarity #140236
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
base: main
Are you sure you want to change the base?
gh-140160: Doc improve PyObject_IsSubclass documentation for clarity #140236
Conversation
…eness Simplify and clarify the wording of PyObject_IsSubclass documentation in the C API reference. pythonGH-140160
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also improve PyObject_IsInstance in this PR.
| Return ``1`` if the class *derived* is identical to or derived from the class | ||
| *cls*, otherwise return ``0``. In case of an error, return ``-1``. | ||
| Return ``1`` if *derived* is a subclass of *cls*, ``0`` if not, or ``-1`` on | ||
| error. | ||
| If *cls* is a tuple, the check will be done against every entry in *cls*. | ||
| The result will be ``1`` when at least one of the checks returns ``1``, | ||
| otherwise it will be ``0``. | ||
| If *cls* has a :meth:`~type.__subclasscheck__` method, it will be called to | ||
| determine the subclass status as described in :pep:`3119`. Otherwise, | ||
| *derived* is a subclass of *cls* if it is a direct or indirect subclass, | ||
| i.e. contained in :attr:`cls.__mro__ <type.__mro__>`. | ||
| If *cls* is a tuple, return ``1`` if *derived* is a subclass of any entry in | ||
| *cls*. | ||
| Normally only class objects, i.e. instances of :class:`type` or a derived | ||
| class, are considered classes. However, objects can override this by having | ||
| a :attr:`~type.__bases__` attribute (which must be a tuple of base classes). | ||
| The check respects :meth:`~type.__subclasscheck__` method if defined (see | ||
| :pep:`3119`); otherwise, checks whether *derived* is in | ||
| :attr:`cls.__mro__ <type.__mro__>`. Non-class objects with a | ||
| :attr:`~type.__bases__` attribute (which must be a tuple of base classes) | ||
| are also supported. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to just say that function is equivalent to the Python-level issubclass function. Then, details regarding __subclasscheck__ can be added there instead.
This PR Simplifies the wording of PyObject_IsSubclass documentation in the C API reference.
PyObject_IsSubclassdocumentation #140160📚 Documentation preview 📚: https://cpython-previews--140236.org.readthedocs.build/