Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-101100: Fix Sphinx warnings inargparse module#103289

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
hugovk merged 7 commits intopython:mainfromhugovk:docs-warnings-argparse
Apr 24, 2023

Conversation

hugovk
Copy link
Member

@hugovkhugovk commentedApr 5, 2023
edited
Loading

Fix Sphinx warnings in theargparse tutorial and library reference, plus add some missing bits tooptparse that are referred to fromargparse.

Before

touch ./Doc/howto/argparse.rst ./Doc/library/argparse.rst; make -C Doc html SPHINXERRORHANDLING=-n2>&1| grep"argparse.*WARNING"| tee>(wc -l)Doc/howto/argparse.rst:14: WARNING: c:func reference target not found: getoptDoc/howto/argparse.rst:140: WARNING: py:meth reference target not found: add_argumentDoc/howto/argparse.rst:146: WARNING: py:meth reference target not found: parse_argsDoc/howto/argparse.rst:257: WARNING: py:attr reference target not found: args.verbosityDoc/howto/argparse.rst:298: WARNING: py:data reference target not found: args.verboseDoc/howto/argparse.rst:672: WARNING: py:meth reference target not found: ArgumentParser.parse_argsDoc/howto/argparse.rst:699: WARNING: py:meth reference target not found: add_mutually_exclusive_groupDoc/library/argparse.rst:587: WARNING: py:func reference target not found: locale.getpreferredencoding(False)Doc/library/argparse.rst:1149: WARNING: py:exc reference target not found: ArgumentTypeErrorDoc/library/argparse.rst:1191: WARNING: py:exc reference target not found: FileNotFoundDoc/library/argparse.rst:1445: WARNING: py:meth reference target not found: add_argumentDoc/library/argparse.rst:1718: WARNING: py:meth reference target not found: ArgumentParser.add_parserDoc/library/argparse.rst:1788: WARNING: py:meth reference target not found: add_parserDoc/library/argparse.rst:2159: WARNING: py:meth reference target not found: parse_known_argsDoc/library/argparse.rst:2288: WARNING: py:class reference target not found: optparse.ValuesDoc/library/argparse.rst:2288: WARNING: py:exc reference target not found: optparse.OptionErrorDoc/library/argparse.rst:2288: WARNING: py:exc reference target not found: optparse.OptionValueErrorDoc/library/argparse.rst:2288: WARNING: py:exc reference target not found: ArgumentError      18

After

I'm not sure how to fix these:

Doc/library/argparse.rst:1718: WARNING: py:meth reference target not found: ArgumentParser.add_parserDoc/library/argparse.rst:1788: WARNING: py:meth reference target not found: add_parser

add_parser is a method of the_SubParsersAction class. Any ideas? Use the! to silence them?

defadd_parser(self,name,**kwargs):

@encukou
Copy link
Member

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_parsershould be documented and mentions of itshould generally be links.

But here, the current documentation is a sentence inArgumentParser.add_subparsers() docs:

This object has a single method, add_parser(), which takes a command name and anyArgumentParser constructor arguments, and returns anArgumentParser 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 toadd_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 toArgumentParser.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.

hugovk and ezio-melotti reacted with thumbs up emoji

@pradyunsg
Copy link
Member

pradyunsg commentedApr 6, 2023
edited
Loading

The option that I prefer would be to change theadd_parser links/missing references into a regular inline code in this PR, and then document theadd_parser method in a follow up. The alternative is documenting theadd_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 theadd_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.

@CAM-GerlachCAM-Gerlach self-requested a reviewApril 6, 2023 16:59
Copy link
Member

@ezio-melottiezio-melotti left a 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 foradd_parser, we would have to add both the_SubParsersAction class and theadd_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 theadd_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 additionalaliases argument, that is mentioned below, but not included in the list of arguments (this should probably be addressed in a separate PR).

hugovk reacted with thumbs up emoji
@CAM-GerlachCAM-Gerlach added the needs backport to 3.11only security fixes labelApr 6, 2023
Copy link
Member

@CAM-GerlachCAM-Gerlach left a comment
edited
Loading

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 givenadd_parser is a method of the special subparsers object (_SubParsersAction), notArgumentParser. Therefore, the one instance of it should at least be changed to justadd_parser like the rest, for this PR at least.

As foradd_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 theOption attributes in theseoptparse 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 theOption/Values classes, if we also choose to do that separately from here) and just leave the valid warnings until then (i.e. don't removeDoc/library/argparse.rst from the ignore list just yet).

hugovk reacted with thumbs up emoji
Comment on lines 7 to 9
.. _argparse-tutorial:

.. currentmodule:: argparse
Copy link
Member

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 theArgparse 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.

hugovk reacted with thumbs up emoji
@CAM-Gerlach
Copy link
Member

CAM-Gerlach commentedApr 7, 2023
edited
Loading

IMO, generally that should be the last-resort. The goal is improving documentation, not getting rid of warnings. IMO, this warning is useful --add_parsershould be documented and mentions of itshould generally be links.

💯

The option that I prefer would be to change theadd_parser links/missing references into a regular inline code in this PR, and then document theadd_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 twooptparse 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 foradd_parser, we would have to add both the_SubParsersAction class and theadd_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 theOption 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 theadd_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 undocumentedaliases 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).

ezio-melotti reacted with eyes emoji

hugovkand others added4 commitsApril 7, 2023 16:25
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>
@hugovk
Copy link
MemberAuthor

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 theOption/Values classes, if we also choose to do that separately from here) and just leave the valid warnings until then (i.e. don't removeDoc/library/argparse.rst from the ignore list just yet).

I included yourOption/Values suggestions here. Fine by me if you'd like to open a followup to documentadd_parser as you suggest 👍

@hugovkhugovk marked this pull request as ready for reviewApril 7, 2023 13:44
Copy link
Member

@CAM-GerlachCAM-Gerlach left a comment
edited
Loading

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).

@hugovk
Copy link
MemberAuthor

@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 :)

hugovkand others added2 commitsApril 24, 2023 15:19
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
@hugovk
Copy link
MemberAuthor

hugovk commentedApr 24, 2023
edited
Loading

At PyCon sprints: we decided to use the nitpick_ignore approach.

Copy link
Member

@CAM-GerlachCAM-Gerlach left a 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 !

@hugovkhugovk merged commit79ae019 intopython:mainApr 24, 2023
@hugovkhugovk deleted the docs-warnings-argparse branchApril 24, 2023 21:36
@miss-islington
Copy link
Contributor

Thanks@hugovk for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry@hugovk, I had trouble checking out the3.11 backport branch.
Please retry by removing and re-adding the "needs backport to 3.11" label.
Alternatively, you can backport usingcherry_picker on the command line.
cherry_picker 79ae019164eeb6b94118bc17bc1e937405684c75 3.11

carljm added a commit to carljm/cpython that referenced this pull requestApr 24, 2023
* 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)
carljm added a commit to carljm/cpython that referenced this pull requestApr 24, 2023
* 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)
@hugovkhugovk added needs backport to 3.11only security fixes and removed needs backport to 3.11only security fixes labelsApr 24, 2023
@miss-islington
Copy link
Contributor

Thanks@hugovk for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry,@hugovk, I could not cleanly backport this to3.11 due to a conflict.
Please backport usingcherry_picker on command line.
cherry_picker 79ae019164eeb6b94118bc17bc1e937405684c75 3.11

hugovk added a commit to hugovk/cpython that referenced this pull requestApr 24, 2023
)Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>(cherry picked from commit79ae019)
@bedevere-bot
Copy link

GH-103803 is a backport of this pull request to the3.11 branch.

@bedevere-botbedevere-bot removed the needs backport to 3.11only security fixes labelApr 24, 2023
hugovk added a commit that referenced this pull requestApr 24, 2023
…103803)Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@AA-TurnerAA-TurnerAA-Turner left review comments

@ezio-melottiezio-melottiezio-melotti left review comments

@CAM-GerlachCAM-GerlachCAM-Gerlach approved these changes

Assignees

@hugovkhugovk

Labels
docsDocumentation in the Doc dirskip news
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

8 participants
@hugovk@encukou@pradyunsg@CAM-Gerlach@miss-islington@bedevere-bot@AA-Turner@ezio-melotti

[8]ページ先頭

©2009-2025 Movatter.jp