Skip to content

argparse: undocumented nargs constants ONE_OR_MORE, OPTIONAL, PARSER, REMAINDER, ZERO_OR_MORE, SUPPRESS #118920

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

Open
rindeal opened this issue May 10, 2024 · 4 comments
Labels
docs Documentation in the Doc dir

Comments

@rindeal
Copy link
Contributor

rindeal commented May 10, 2024

Concerning the possible values of the nargs parameter of add_argument().

The following values are already described in the documentation, so only a mention of the constants is needed:

  • OPTIONAL = ?
  • ZERO_OR_MORE = *
  • ONE_OR_MORE = +

The following constants and their values do not seem to be documented anywhere:

  • PARSER
  • REMAINDER

SUPPRESS constant was documented for help parameter in #53595, but not for nargs.

@rindeal rindeal added the docs Documentation in the Doc dir label May 10, 2024
@rindeal rindeal changed the title argparse: undocumented nargs constants ONE_OR_MORE, OPTIONAL, PARSER, REMAINDER, ZERO_OR_MORE argparse: undocumented nargs constants ONE_OR_MORE, OPTIONAL, PARSER, REMAINDER, ZERO_OR_MORE, SUPPRESS May 10, 2024
@vadmium
Copy link
Member

vadmium commented May 10, 2024

The nargs=REMAINDER documentation was removed on purpose in #61252; see also #101472

@savannahostrowski
Copy link
Member

savannahostrowski commented Sep 18, 2024

I'm not really convinced that we should do this. While we could document these constants for completeness, doing so would probably add unnecessary redundancy to the docs and potentially confuse newer users.

Using *, +, ?, etc. is far and away more common than using these constants
(e.g., nargs='*' has 110k hits vs. nargs=argparse.ZERO_OR_MORE has 96 hits). There are probably some scenarios where folks might want to use the constants (e.g., linters, editors/autocomplete), but again, the search yielded few results...leading me to believe this is uncommon.

A cursory search on GitHub also showed very little usage for PARSER and SUPPRESS. To the best of my knowledge, unlike REMAINDER, these were never documented.

@rindeal
Copy link
Contributor Author

rindeal commented Sep 19, 2024

I'm not really convinced that we should do this. While we could document these constants for completeness, doing so would probably add unnecessary redundancy to the docs and potentially confuse newer users.

Using *, +, ?, etc. is far and away more common than using these constants (e.g., nargs='*' has 110k hits vs. nargs=argparse.ZERO_OR_MORE has 96 hits). There are probably some scenarios where folks might want to use the constants (e.g., linters, editors/autocomplete), but again, the search yielded few results...leading me to believe this is uncommon.

A cursory search on GitHub also showed very little usage for PARSER and SUPPRESS. To the best of my knowledge, unlike REMAINDER, these were never documented.

Thank you for your input @savannahostrowski. However, the argument based on search frequency may reflect a statistical bias. The low usage of these constants could be a direct result of their lack of documentation, rather than an indication of their irrelevance or redundancy. Proper documentation could potentially increase their usage, especially in scenarios where constants are preferred for clarity or consistency (e.g., linters, editors/autocomplete). Therefore, documenting these constants would enhance completeness and potentially benefit users who prefer or require explicit constants.

@rindeal
Copy link
Contributor Author

rindeal commented Sep 19, 2024

#118920 (comment):

The nargs=REMAINDER documentation was removed on purpose in #61252; see also #101472

The decision was highly sub-optimal, like sweeping the problems under the rug. It would have been far better to either deprecate and remove it or clearly document it as a legacy, buggy feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
Status: Doc issues
Development

No branches or pull requests

3 participants