-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
Accommodate Sphinx option by changing docstring return type of "integer" to "int". #100989
Comments
You can change "integer" to "int" if you like. The other changes look gratuitous. Also, PEP 7 predates modern type annotations. Doc strings are allowed to put any text as the return type as long as it is interpretable by a human. It is unfortunate that Sphinx is assuming otherwise. How would it handle user defined types or types defined in type comments? |
collections.deque
not compliant to PEP-7
Ok, thanks for your feedback!
Still, changing it to cpython/Modules/atexitmodule.c Line 211 in 0ace820
cpython/Modules/_threadmodule.c Line 190 in 762745a
Line 28 in 81f7359
Although to be fair, I also found quite a few other modules which use an inconsistent format, e.g. Line 160 in 3e06b50
which I would change to time() -> float to match the correct type and allow the cross-referencing between documentations.
Are there better options to annotate types in C modules? If so, I think it should be mentioned in the docs of
User defined types are usually documented in the project that Sphinx is invoked in, and thus it'll find the reference to the custom type. |
@rhettinger Do you have any more thoughts on this? Anything specific you want me to change in the PR? |
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
…pythonGH-100990) (cherry picked from commit c740736) Co-authored-by: Timo Ludwig <ti.ludwig@web.de> Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
…pythonGH-100990) (cherry picked from commit c740736) Co-authored-by: Timo Ludwig <ti.ludwig@web.de> Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
These edits violate the rules for writing docstrings:
As a consequence, user's seeing a summary line in tool tips no longer see anything useful. Previous tooltips: New tooltips: |
Also, it seems to me that the checkin title was misleading, "Improve accuracy of docstrings". In none of the cases were the docstrings inaccurate. These were almost purely stylistic edits and should not be backported. |
This is correct; I see now that my review has been incomplete. @timoludwig, please create a follow-up PR that revert this regression. Regarding backporting: we do backport doc updates/fixes, including docstrings, to bug-fix branches. This also include stylistic fixes. This reduces the risk of conflicts when other PRs are backported. |
Sorry, I was not aware of that side effect. Just to wrap this up: We have two conventions that are mutually exclusive: The general docstring rule says that we have to write a summary in the first line that is readable for humans and can be displayed as tooltip, and the rule for C modules says that we should write a line that can be parsed by automatic tools to retrieve the function signature. In order to find a compromise, I see different options:
Which one of those would be your preferred solution? (Or do you have other suggestions?) |
IMO, docstrings should be written for humans; no matter if we're talking about extension modules or pure Python modules. The "title" line should IMO be a succinct description of the method/function; any detailed description follow two newlines below, like any well-written git commit message. See also PEP-257, which has a lot of good observations on what a good docstring is. |
@erlend-aasland Ok, sounds reasonable. Does that mean option 1. (removing the signature from the summary line)? Or does it depend on the complexity of the function signature, e.g. for
Whereas for a simple
|
…deque" This reverts commit 317f39b.
…cstrings (python#100990)" This reverts commit c740736.
…cstrings (python#100990)" This reverts commit c740736.
…strings (pythonGH-102979) (cherry picked from commit 7f01a11) Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
…strings (pythonGH-102979) (cherry picked from commit 7f01a11) Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
@timoludwig Would it solve your problem if I just removed the |
@rhettinger Yes, Sphinx uses this regex to determine whether a docstring line is a signature, and without the I could however also open a ticket on Sphinx' side to ignore everything after Thanks a lot for revisiting this issue! |
(cherry picked from commit d494091) Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
Thanks for the report. |
…python#100990) Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
…python#100990) Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
Bug report
When
collections.deque
is subclassed and the resulting class is documented with Sphinx using the option:inherited-members:
, the following error appears:I assume this is because the
PyDoc_STRVAR
docstring of the C-implementation is not compliant to PEP-7 as required inPyDoc_STRVAR
:cpython/Modules/_collectionsmodule.c
Lines 992 to 993 in d9dff4c
And everything after
->
is interpreted as type hint.This can be reproduced with e.g. a python module
sub_deque.py
:and a documenation file
docs/src/sub_deque.rst
:which is then built with Sphinx:
sphinx-build -W docs/src docs/dist
.I'd be happy to provide a patch for this myself if you feel this issue should be fixed.
Your environment
Linked PRs
collections.deque
#100990The text was updated successfully, but these errors were encountered: