Sorry, something went wrong.
|
Use the ! to silence them? IMO, generally that should be the last-resort. The goal is improving documentation, not getting rid of warnings. IMO, this warning is useful -- add_parser should be documented and mentions of it should generally be links. But here, the current documentation is a sentence in ArgumentParser.add_subparsers() docs: This object has a single method, add_parser(), which takes a command name and any ArgumentParser constructor arguments, and returns an ArgumentParser object that can be modified as usual. And I guess that's fine in this case. It's in the same section as the would-be links to add_parser, so silencing them sounds OK in this particular case. The downside is that nothing outside this section (incl. third-party Intersphinx users) needs to link to ArgumentParser.add_subparsers instead. 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. |
Sorry, something went wrong.
|
The option that I prefer would be to change the add_parser links/missing references into a regular inline code in this PR, and then document the add_parser method in a follow up. The alternative is documenting the add_parser method or reworking the API of the module around the subparser within this PR -- which is doing multiple things in a single PR and adding to the scope of the PR. That said, I'm not opposed to having just the add_parser method get documented in this PR -- it's just that I don't see a direct/obvious way to document that, and figuring the details of that out is reasonable to defer to a follow up change IMO. |
Sorry, something went wrong.
There was a problem hiding this comment.
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).
Sorry, something went wrong.
There was a problem hiding this comment.
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).
Sorry, something went wrong.
| .. _argparse-tutorial: | ||
|
|
||
| .. currentmodule:: argparse |
There was a problem hiding this comment.
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.
Sorry, something went wrong.
|
IMO, generally that should be the last-resort. The goal is improving documentation, not getting rid of warnings. IMO, this warning is useful -- add_parser should be documented and mentions of it should generally be links. 💯 The option that I prefer would be to change the add_parser links/missing references into a regular inline code in this PR, and then document the add_parser method in a follow up. 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 optparse classes I highlight above, to one or more followup PRs that that's totally fine too of course. 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 ! to de-resolve the reference, rather than converting it to a whole different type with different semantics and output formatting.) 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). There's actually no need to explicitly document the _SubParsersAction class; you can just add a standalone method with the class prefixed, just like the the Option attributes are prior to this PR, without the class being separately documented. E.g.: .. method:: _SubParsersAction.add_parser(name, **kwargs)
Description...
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. 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 aliases argument, as desired) without documenting the class, it seems reasonable to just properly document the method directly instead (either in this PR, or perhaps more pragmatically in a follow-up where we can discuss this further). |
Sorry, something went wrong.
|
Thanks all for the reviews! I changed both :meth:`~ArgumentParser.add_parser` and :meth:`add_parser` to :meth:`!add_parser` 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). I included your Option/Values suggestions here. Fine by me if you'd like to open a followup to document add_parser as you suggest 👍 |
Sorry, something went wrong.
There was a problem hiding this comment.
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).
Sorry, something went wrong.
|
@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 :) |
Sorry, something went wrong.
|
At PyCon sprints: we decided to use the nitpick_ignore approach. |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM now, thanks @hugovk !
Sorry, something went wrong.
|
Thanks @hugovk for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11. |
Sorry, something went wrong.
|
Sorry @hugovk, I had trouble checking out the 3.11 backport branch. |
Sorry, something went wrong.
|
Thanks @hugovk for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11. |
Sorry, something went wrong.
|
Sorry, @hugovk, I could not cleanly backport this to 3.11 due to a conflict. |
Sorry, something went wrong.
|
GH-103803 is a backport of this pull request to the 3.11 branch. |
Sorry, something went wrong.
Fix Sphinx warnings in the argparse tutorial and library reference, plus add some missing bits to optparse that are referred to from argparse.
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