10000 bpo-21150: add quick link/summary table to the top of argparse documentation by suhearsawho · Pull Request #12005 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-21150: add quick link/summary table to the top of argparse documentation #12005

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

Merged
merged 8 commits into from
Apr 18, 2022
Prev Previous commit
Wrapped long lines of paragraphs under Core functionality section and…
… removed backtick marks around source links to maintain consistency throughout file
  • Loading branch information
suhearsawho committed Feb 25, 2019
commit 8b35e391415d2025792a2f6eb85669ea5542a9f6
34 changes: 21 additions & 13 deletions Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,22 @@ Summary
Core Functionality
^^^^^^^^^^^^^^^^^^

The :mod:`argparse` module's support for command-line interfaces is built from the following:
The :mod:`argparse` module's support for command-line interfaces is built
from the following:

The :class:`argparse.ArgumentParser` creates a new :class:`ArgumentParser` object. Commonly used arguments include `prog`_, `description`_, and `formatter_class`_. For example, the user can create an instance of :class:`ArgumentParser` through the following::
The :class:`argparse.ArgumentParser` creates a new :class:`ArgumentParser`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a suggestion, as they points to the exact same place, it may be lighter by removing this 2nd link. Also it's obvious a class creates an instance of itself.

Suggested change
The :class:`argparse.ArgumentParser` creates a new :class:`ArgumentParser`
The :class:`argparse.ArgumentParser` creates a new parser

object. Commonly used arguments include prog_, description_, and
formatter_class_. For example, the user can create an instance of
Copy link
Member
@JulienPalard JulienPalard Sep 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the user often mention the person using the Python program, not the person writing it. Maybe just remove this sentence and remplace by a simple "Example::" ?

Yes I also try to shorten your paragraph a bit: it's just an introduction, the real thing is documented further down, so if you want for it to be read you have to keep it short, people tend to just skip the introductions.

:class:`ArgumentParser` through the following::

>>> parser = argparse.ArgumentParser(prog='PROG', description='DESC',
... formatter_class=argparse.RawDescriptionHelpFormatter)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is too long (spawns an horizontal scrollbar in the example box, in the rendered HTML), can you please use hanging indentation, like:

parser = argparse.ArgumentParser(
    prog="PROG",
    description="DESC",
    formatter_class=argparse.RawDescriptionHelpFormatter,
)


The :func:`ArgumentParser.add_argument` is a function that is used to define how a single command-line argument should be parsed. Commonly used arguments include `name or flags`_, `action`_, `default`_, `type`_, `required`_, and `help`_. An example of the function :func:`ArgumentParser.add_argument` is as follows::
The :func:`ArgumentParser.add_argument` is a function that is used
to define how a single command-line argument should be parsed. Commonly used
arguments include `name or flags`_, action_, default_, type_, required_,
and help_. An example of the function :func:`ArgumentParser.add_argument`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, you could drop the last sentence, its single link is redundent, make the paragraph a bit long, and add no real information, "Example::" is enough.

is as follows::

>>> parser.add_argument('-v', '--verbose', action='store_true',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency please also use hanging indentation here, with a single argument per line.

... help='Show various debugging information')
Expand All @@ -64,10 +72,10 @@ Optional ``'-v'``, ``'--verbose'``
====================== =========================================================== =========================================================================================================================
Name Description Keywords
====================== =========================================================== =========================================================================================================================
`action`_ Specifies how an argument should be handled ``'store'``, ``'store_const'``, ``'store_true'``, ``'append'``, ``'append_const'``, ``'count'``, ``'help'``, ``'version'``
`default`_ Default value used when an argument is not provided
`type`_ Automatically converts an argument to the given type :class:`int`, :class:`float`, :class:`bool`, ``argparse.FileType('w')``, ``callable function``
`help`_ Help message of an argument
action_ Specifies how an argument should be handled ``'store'``, ``'store_const'``, ``'store_true'``, ``'append'``, ``'append_const'``, ``'count'``, ``'help'``, ``'version'``
default_ Default value used when an argument is not provided
type_ 849D Automatically converts an argument to the given type :class:`int`, :class:`float`, :class:`bool`, ``argparse.FileType('w')``, ``callable function``
help_ Help message of an argument
====================== =========================================================== =========================================================================================================================


Expand All @@ -77,12 +85,12 @@ Name Description
====================== =========================================================== =======================================================================================================================
Name Description Keywords
====================== =========================================================== =======================================================================================================================
`nargs`_ Associates a single action with the number of arguments ``N`` (:class:`int`), ``'?'``, ``'*'``, ``'+'``, ``argparse.REMAINDER``
`const`_ Stores constant values of names or flags
`choices`_ A container that lists the possible values ``['foo', 'bar']``, ``range(1, 10)``, Any object that supports ``in`` operator
`required`_ Indicates if an optional argument is required or not ``True``, ``False``
`metavar`_ An alternative display name for the argument
`dest`_ Specifies name of attribute to be used in ``parse_args()``
nargs_ Associates a single action with the number of arguments ``N`` (:class:`int`), ``'?'``, ``'*'``, ``'+'``, ``argparse.REMAINDER``
const_ Stores constant values of names or flags
choices_ A container that lists the possible values ``['foo', 'bar']``, ``range(1, 10)``, Any object that supports ``in`` operator
required_ Indicates if an optional argument is required or not ``True``, ``False``
metavar_ An alternative display name for the argument
dest_ Specifies name of attribute to be used in ``parse_args()``
====================== =========================================================== =======================================================================================================================


Expand Down
0