-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Summary tables for argparse add_argument options #58058
Comments
With the current argparse docs, it's very hard to get a quick reminder of how to spell the various parameters for add_argument, and just what they do. This issue suggests adding a "Quick Reference" section for add_argument, with the following elements:
|
Looking at the docs, a 4th table in the quick reference section would be useful: the parameters for ArgumentParser itself. Note that the ArgumentParser and add_arguments() parameters are already summarised in their respective entries, but there are currently no summaries at all for the possible "action" and "nargs" values |
Creating the tables should not be too hard, especially using e.g. org-mode, but:
Maybe a good alternative would be to build a table style for info fields lists and to use :param: wherever that belongs? Or the doc could be split into a "quickstart" with just a listing of arguments and a *very simple* example or two, and then the exhaustive documentation, which could even be a separate document? |
My specific suggestion is to have a dedicated "Quick Reference" section before the first example. This section would be aimed at two groups of people:
Since the heart of argparse is the ability to map arguments to actions, I'd suggest the quick reference section actually lead with a table of "actions" that argparse natively supports, along with a final entry pointing to the information on custom actions (i.e. subclasses of argparse.Action). Likely columns for this first table: Action Name, Description, Parameters The "Parameters" column would span multiple lines, with one parameter and a brief description of the parameter on each line. The second table could then just be a short summary of the various 'nargs' values. Repeating the list of parameters to ArgumentParser in the quick reference section probably isn't necessary, and the short parameter descriptions in the actions table should suffice for add_argument(). |
OK, that looks like a good plan. |
Sounds like an excellent plan to me too. |
I started looking into that, and it turns out that's more annoying than expected: a bunch of parameters are shared by many (to all) actions, leading to lots of duplications in the table. And the full matrix of actions to parameters is not really explained in the doc. In fact, I'm coming around to thinking a matrix of the interaction between actions and arguments could be better and clearer than a table of actions with parameters bunched together at the end. In any case, it would certainly be more maintainable... except for rST not really having support for attributes on data tables, and (as far as I can tell) can't handle horizontal headers. |
Having a second table of "Applicable Parameters" could definitely work. I don't think the "no horizontal headers" limitation should be a big problem - the matrix should be readable even if the action names are just listed in an ordinary column. |
+1 from me. The docs in their present form are a great tutorial but are a total failure as a quick reference. Besides having table of parameters, it may also be worthwhile to move some of the examples to a HOWTO document (much as was done with the logging package). |
Had some time to play with this today, here's a draft matrix of actions and add_argument parameters which is pretty readable, but:
I also tried my hand at formatting |
completion for list item 4:
|
Indeed. Maybe this should be moved down in the page, and possibly provide a link to the top (see e.g. the unittest doc 0 and the link on top to jump to the list of assert methods). Once people know it's there they will find it easily, but opening the doc with this table is a bit confusing IMHO. Adding a couple of line to explain what the table is for might also help.
In the rst source only latin-1 chars are allowed (otherwise
You can also add notes numbers just next to the "x"s and add a description below [1]. This could be applied to the "const" column as well if you want to save some horizontal space. If you want to save even more space you could remove the version row/column and add a note about it.
Maybe you could add a note about this too.
This might be useful (I did it in the assert methods' tables in the unittest doc 0), and having links in the HTML probably outweighs the fact that the rst source becomes less readable. Note that (depending on what you change), you might be able to use the lightweight syntax for tables if you prefer. [1]: e.g. http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex |
At a quick glance the patch looks okay to me so as there's been a lot of positive comments can we have a formal patch review please. |
Just updated this patch with "x" instead of the unicode character. |
On 13 Apr 2015, at 10:56, Stéphane Wirtel wrote:
Sorry bad patch, I have read the last comment (“replace by x or |
Created Quick Reference table subsection under the add_argument() method section - used the table originally created by xmorel, replacing ticks with 'x' and adding links to the sections in the documentation for each parameter names. Removed the 'version' column and row as that wasn't adding much info. There is also a link to the quick reference subsection at the top of the page. |
I think it would be better to move the summary table to the end (just before the Action section), and add another link to the summary to the sentence "The following sections describe how each of these are used." That is, follow that sentence with something like 'a summary table of the relevance of each paramter to the various possible actions is given at the end of the section', with a link on summary table. Otherwise, the patch looks good to me. |
Hi all, If you think the patch is ok, please merge it, we will close this issue. Thanks |
just for 2.7, 3.7 & 3.8 because they are in bugfix mode. |
I like the idea of having various summary tables for argparse, but the one in the PR isn't visually attractive or self-explanatory. |
Hi @Raymond, Yep, I understand about the "look", I have seen the result after the build of the doc but the patch was like that and I did not want to change the initial patch. Would you suggest one layout and I could update the PR with your recommendations? Thanks for your review |
I close my PR, if anyone wants to submit an other PR, feel free to do it. |
* main: (69 commits) Add "annotate" SET_FUNCTION_ATTRIBUTE bit to dis. (python#124566) pythongh-124412: Add helpers for converting annotations to source format (python#124551) pythongh-119180: Disallow instantiation of ConstEvaluator objects (python#124561) For-else deserves its own section in the tutorial (python#123946) Add 3.13 as a version option to the crash issue template (python#124560) pythongh-123242: Note that type.__annotations__ may not exist (python#124557) pythongh-119180: Make FORWARDREF format look at __annotations__ first (python#124479) pythonGH-58058: Add quick reference for `ArgumentParser` to argparse docs (pythongh-124227) pythongh-41431: Add `datetime.time.strptime()` and `datetime.date.strptime()` (python#120752) pythongh-102450: Add ISO-8601 alternative for midnight to `fromisoformat()` calls. (python#105856) pythongh-124370: Add "howto" for free-threaded Python (python#124371) pythongh-121277: Allow `.. versionadded:: next` in docs (pythonGH-121278) pythongh-119400: make_ssl_certs: update reference test data automatically, pass in expiration dates as parameters python#119400 (pythonGH-119401) pythongh-119180: Avoid going through AST and eval() when possible in annotationlib (python#124337) pythongh-124448: Update Windows builds to use Tcl/Tk 8.6.15 (pythonGH-124449) pythongh-123884 Tee of tee was not producing n independent iterators (pythongh-124490) pythongh-124378: Update test_ttk for Tcl/Tk 8.6.15 (pythonGH-124542) pythongh-124513: Check args in framelocalsproxy_new() (python#124515) pythongh-101100: Add a table of class attributes to the "Custom classes" section of the data model docs (python#124480) Doc: Use ``major.minor`` for documentation distribution archive filenames (python#124489) ...
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
ArgumentParser
to argparse docs #124227The text was updated successfully, but these errors were encountered: