-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
bpo-38787: Clarify docs for PyType_GetModule and warn against common mistake #20215
Conversation
Doc/c-api/type.rst
Outdated
may not return the intended result. | ||
``Py_TYPE(self)`` may be a *subclass* of the intended class, and subclasses | ||
are not necessarily defined in the same module as their superclass. | ||
See :c:type:`PyCMethod` to get the defining class. |
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.
The "defining class" is something new to me. PyCMethod mentions it without explining it. Would it be possible to define it somewhere? And then link to it.
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.
Do you think the explanation should be in PyCMethod
docs, or in METH_METHOD | METH_FASTCALL | METH_KEYWORDS
docs?
For the other conventions, the docs for the flags have more detail. But I haven't found a way to link to METH_METHOD | METH_FASTCALL | METH_KEYWORDS
.
I suggest to add a short section about subclassing and defining class at the bottom of https://docs.python.org/dev/c-api/type.html and then add links to this section. Something similar to https://docs.python.org/dev/library/os.html#file-descriptor-operations which defines what a file descriptor is. |
What do you think the section should say? Does it need more detail than:
A whole section seems like overkill to me. |
Explain |
Ah, maybe also point the right section of the PEP 573 for more information? |
+1 IMHO, we don't need explain too much details in docs ; ) |
No. The PEP is an immutable document about the design and discussion. It should be superseded by the documentation. OK. I meant this as a quick fix, but it looks like I'll need more time to write this up. |
According to the length of the following PEP sections, it seems like there are few things to say about defining classes :-) |
I'm now writing a HOWTO on multi-phase init, heap types and avoiding static state, so that everything is explained properly in context. However, this full overview will take a long time to put together. I agree that the docs in this PR are very terse and technical, but I believe they are an improvement. Consider not blocking the PR on the long explanation. |
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.
LGTM. This change enhances the doc.
Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9. |
…mistake (pythonGH-20215) (cherry picked from commit d9a966a) Co-authored-by: Petr Viktorin <encukou@gmail.com>
GH-21984 is a backport of this pull request to the 3.9 branch. |
Thanks @encukou for this PR and the PEP 630! |
This should make
PyType_GetModule
, andPyType_FromModuleAndSpec
's module argument clearer to people who didn't read the PEP.Thanks @vstinner and @shihai1991 for asking clarifying questions. Hopefully this will help others.
https://bugs.python.org/issue38787
Automerge-Triggered-By: @encukou