Skip to content

gh-91118: Fix docstrings that do not honor --without-doc-strings #31769

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

Merged
merged 12 commits into from
Apr 18, 2022

Conversation

arhadthedev
Copy link
Member

@arhadthedev arhadthedev commented Mar 8, 2022

To support --without-doc-strings, all docstrings must be wrapped into PyDoc_STRVAR or PyDoc_STR (PEP 7). However, there are 18 occurrences in code and 10 in C API documentation that do not follow this rule. The documentation is important too because it should not teach people the wrong things.

To find the occurrences I searched for (?:^\s*.tp_doc = "|" \/\* tp_doc \*\/$) and^(?:static\s+)?const\s+char\s+[^=]+=\s*".

Fixes GH-91118.

@arhadthedev arhadthedev marked this pull request as ready for review March 8, 2022 19:52
Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

There are a bunch of others, mostly in ctypes:

% git grep '".*tp_doc\s*'
Doc/c-api/typeobj.rst:       "My objects",                   /* tp_doc */
Modules/_ctypes/_ctypes.c:    "deletes a key from a dictionary",          /* tp_doc */
Modules/_ctypes/_ctypes.c:    "metatype for the CData Objects",           /* tp_doc */
Modules/_ctypes/_ctypes.c:    "metatype for the CData Objects",           /* tp_doc */
Modules/_ctypes/_ctypes.c:    "metatype for the Pointer Objects",         /* tp_doc */
Modules/_ctypes/_ctypes.c:    "metatype for the Array Objects",           /* tp_doc */
Modules/_ctypes/_ctypes.c:    "metatype for the PyCSimpleType Objects",           /* tp_doc */
Modules/_ctypes/_ctypes.c:    "metatype for C function pointers",         /* tp_doc */
Modules/_ctypes/_ctypes.c:    "XXX to be provided",                       /* tp_doc */
Modules/_ctypes/_ctypes.c:    "Function Pointer",                         /* tp_doc */
Modules/_ctypes/_ctypes.c:    "Structure base class",                     /* tp_doc */
Modules/_ctypes/_ctypes.c:    "Union base class",                         /* tp_doc */
Modules/_ctypes/_ctypes.c:    "XXX to be provided",                       /* tp_doc */
Modules/_ctypes/_ctypes.c:    "XXX to be provided",                       /* tp_doc */
Modules/_ctypes/_ctypes.c:    "XXX to be provided",                       /* tp_doc */
Modules/_ctypes/callbacks.c:    "CThunkObject",                             /* tp_doc */
Modules/_ctypes/cfield.c:    "Structure/Union member",                   /* tp_doc */
Modules/_testcapimodule.c:    "Instantiating this exception starts infinite recursion.", /* tp_doc */

I'm a bit skeptical about how useful this is, though—does anyone actually use the configure option to strip docstrings?

:func:`ctypes.CopyComPointer`, :func:`ctypes.FormatError`,
:func:`ctypes.FreeLibrary`, :func:`ctypes.LoadLibrary`, and
:func:`ctypes.sizeof`, along with a bunch of methods in
:class:`~_ctypes.PyCPointerType:, :class:`~_ctypes.PyCSimpleType:, and
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
:class:`~_ctypes.PyCPointerType:, :class:`~_ctypes.PyCSimpleType:, and
:class:`~_ctypes.PyCPointerType`, :class:`~_ctypes.PyCSimpleType`, and

:func:`ctypes.FreeLibrary`, :func:`ctypes.LoadLibrary`, and
:func:`ctypes.sizeof`, along with a bunch of methods in
:class:`~_ctypes.PyCPointerType:, :class:`~_ctypes.PyCSimpleType:, and
:class:`~_ctypes.PyCStructType:.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
:class:`~_ctypes.PyCStructType:.
:class:`~_ctypes.PyCStructType`.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm a bit skeptical about how useful this is, though—does anyone actually use the configure option to strip docstrings?

I think that if a flag exists, it should work fully. Also it's enabled by default so strings that should not be in the binary are no longer there.

@arhadthedev arhadthedev changed the title bpo-46962: Fix docstrings that do not honor --without-doc-strings gh-91118: Fix docstrings that do not honor --without-doc-strings Apr 10, 2022
@arhadthedev arhadthedev reopened this Apr 17, 2022
@JelleZijlstra JelleZijlstra self-requested a review April 17, 2022 19:59
@JelleZijlstra JelleZijlstra self-assigned this Apr 17, 2022
@JelleZijlstra JelleZijlstra added needs backport to 3.9 only security fixes needs backport to 3.10 only security fixes labels Apr 18, 2022
@miss-islington
Copy link
Contributor

Thanks @arhadthedev for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Thanks @arhadthedev for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @arhadthedev and @JelleZijlstra, I could not cleanly backport this to 3.9 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker a573cb2fec664c645ab744658d7e941d72e1a398 3.9

@miss-islington
Copy link
Contributor

Sorry @arhadthedev and @JelleZijlstra, I had trouble checking out the 3.10 backport branch.
Please backport using cherry_picker on command line.
cherry_picker a573cb2fec664c645ab744658d7e941d72e1a398 3.10

@JelleZijlstra
Copy link
Member

@arhadthedev do you want to do the backports? I feel like the docs changes are most important to backport.

@arhadthedev arhadthedev deleted the ctypes-without-doc-string branch April 18, 2022 03:45
arhadthedev added a commit to arhadthedev/cpython that referenced this pull request Apr 18, 2022
…-strings (pythonGH-31769)

Co-authored-by: Éric <merwok@netwok.org>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit a573cb2)

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Apr 18, 2022
@bedevere-bot
Copy link

GH-91662 is a backport of this pull request to the 3.10 branch.

arhadthedev added a commit to arhadthedev/cpython that referenced this pull request Apr 18, 2022
python#31769)

Co-authored-by: Éric <merwok@netwok.org>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit a573cb2)
@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Apr 18, 2022
@bedevere-bot
Copy link

GH-91663 is a backport of this pull request to the 3.9 branch.

@arhadthedev
Copy link
Member Author

That backport to 3.9 was targeted to main instead of 3.9.

The new, correct entry is GH-91664.

JelleZijlstra added a commit that referenced this pull request Apr 19, 2022
GH-31769) (#91664)

Co-authored-by: Éric <merwok@netwok.org>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit a573cb2)
JelleZijlstra pushed a commit that referenced this pull request Apr 19, 2022
…gs (GH-31769) (#91662)

Co-authored-by: Éric <merwok@netwok.org>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit a573cb2)

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
hello-adam pushed a commit to hello-adam/cpython that referenced this pull request Jun 2, 2022
…strings (pythonGH-31769) (python#91664)

Co-authored-by: Éric <merwok@netwok.org>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit a573cb2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix docstrings that do not honor --without-doc-strings
6 participants