-
-
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
gh-101100: Fix Sphinx warnings in argparse
module
#103289
Conversation
IMO, generally that should be the last-resort. The goal is improving documentation, not getting rid of warnings. IMO, this warning is useful -- But here, the current documentation is a sentence in
And I guess that's fine in this case. It's in the same section as the would-be links to If the class was bigger, and it would be clearer to use a concrete name rather than “special action object”, we'd want to document it. And perhaps even rename it in code to remove the underscore (or introduce a public superclass). Public names for helper classes are useful for typing, if nothing else. |
The option that I prefer would be to change the That said, I'm not opposed to having just the |
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.
ISTM that in order to have a proper link for add_parser
, we would have to add both the _SubParsersAction
class and the add_parser
method under it. Doing so will end up adding more churn and making the docs more confusing, unless there is a way to e.g. hide the class and only document the method (and even in that case it might not be worth the trouble).
Furthermore this method is only relevant while working with subparser, so if a link is needed, linking to the add_subparsers
method or the "Sub-commands" sections are both acceptable solutions.
IOW, using !
is fine with me.
On an unrelated note, add_parser
seems to support an additional aliases
argument, that is mentioned below, but not included in the list of arguments (this should probably be addressed in a separate PR).
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.
Sorry for the very long delay finally finishing this; we had some severe weather and I wanted to give it another round of thought.
ArgumentParser.add_parser
is only used once, likely by mistake, as it is clearly incorrect and potentially misleading given add_parser
is a method of the special subparsers object (_SubParsersAction
), not ArgumentParser
. Therefore, the one instance of it should at least be changed to just add_parser
like the rest, for this PR at least.
As for add_parser
itself, given it is referenced a number of times throughout the docs, we should explicitly (even if briefly) formally document it in some form, I would suggest just as a standalone method (prefixed with the class name), since you can document a method, attribute, etc. standalone without having to actually document the class by including the class prefix in the directive, like the Option
attributes in these optparse
docs currently do.
If @hugovk and/or people prefer, that could be addressed in a separate followup PR by Hugo or myself (either together or separately from properly documenting the Option
/Values
classes, if we also choose to do that separately from here) and just leave the valid warnings until then (i.e. don't remove Doc/library/argparse.rst
from the ignore list just yet).
Doc/howto/argparse.rst
Outdated
.. _argparse-tutorial: | ||
|
||
.. currentmodule:: argparse |
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.
This technically means that the ref label above is pointing to the currentmodule directive as its target, rather than the paragraph. however, it should point to the top-level heading instead, so moving _argparse-tutorial:
to right above the Argparse Tutorial
heading will fix it. It won't affect backward compat as existing referents will still point to this page (except the top, as intended, rather than slightly down), while now allowing new referants to automatically use the document title if desired.
💯
As illustrated below, it seems to be relatively straightforward to just add this as a standalone method without documenting the class. That said, if people prefer deferring documenting it, as well as possibly the two If we do defer it, though, we shouldn't silence the legitimate warnings, as they are genuine reminders of missing documentation—arguably among the most important and valuable here, as missing docs is a lot more meaningful to readers than one object name not being a link, and harder for other tooling to spot than just a typo in a ref target. (And at the very least, if we did, the way to do so would be just adding a
There's actually no need to explicitly document the .. method:: _SubParsersAction.add_parser(name, **kwargs)
Description...
Right, but the method is referenced a decent number of places, particularly in examples, and it would mean the method itself couldn't be linked, you'd have to manually link to the section which is more work for writers and somewhat klunky for readers. It also means the method won't show up in searches or in the index. Since it is in fact quite straightforward to add the standalone method (and document the additional undocumented |
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM> Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>
Thanks all for the reviews! I changed both
I included your |
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.
As mentioned previously, I strongly feel we shouldn't silence valid warnings just to quiet a linter when they are legitimate reminders of missing documentation—arguably among the most important and valuable here, as missing docs is a lot more meaningful to readers than one object name not being a link, and harder for other tooling to spot than just a typo in a ref target. Furthermore, it means these links will automatically start working when we add the reference docs, without having to (remember to) manually search for and remove the it makes it easy to spot the instances that need to be updated (or in most cases, they just start working automagically when its fixed), without needing to remember to do a manual search.!
.
Therefore, given the aforementioned potential obstacles to documenting this were cleared up, I suggest we leave this valid warning until fixed in the aforementioned followup (or we decide what else to do with it there).
@CAM-Gerlach We're in no rush to get this one merged. Would you like to make the followup suggestions as a PR to my branch? https://github.com/hugovk/cpython/tree/docs-warnings-argparse Then I can merge it and it'll update this PR :) |
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
…cannot be resolved
At PyCon sprints: we decided to use the nitpick_ignore approach. |
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 now, thanks @hugovk !
Thanks @hugovk for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11. |
Sorry @hugovk, I had trouble checking out the |
* main: pythongh-100227: Only Use deepfreeze for the Main Interpreter (pythongh-103794) pythongh-103492: Clarify SyntaxWarning with literal comparison (python#103493) pythongh-101100: Fix Sphinx warnings in `argparse` module (python#103289)
* superopt: pythongh-100227: Only Use deepfreeze for the Main Interpreter (pythongh-103794) pythongh-103492: Clarify SyntaxWarning with literal comparison (python#103493) pythongh-101100: Fix Sphinx warnings in `argparse` module (python#103289)
Thanks @hugovk for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11. |
Sorry, @hugovk, I could not cleanly backport this to |
) Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM> Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com> (cherry picked from commit 79ae019)
GH-103803 is a backport of this pull request to the 3.11 branch. |
Fix Sphinx warnings in the
argparse
tutorial and library reference, plus add some missing bits tooptparse
that are referred to fromargparse
.Before
After
I'm not sure how to fix these:
add_parser
is a method of the_SubParsersAction
class. Any ideas? Use the!
to silence them?cpython/Lib/argparse.py
Line 1184 in de18267