Skip to content

Commit 07327c2

Browse files
authored
fix incorrect statement in argparse docs
The documentation for the name or flags argument of `argparse.ArgumentParser.add_argument()` said > By default, argparse automatically handles the internal naming and display names of arguments … The dest parametre defaults to the argument name with underscores `_` replacing hyphens `-` . However, this is not true for positional arguments, which retain their hyphens. The documentation for the dest parameter correctly describes this behavior, but a user who only reads the name or flags documentation will be misled. Thus, I added a qualification to the sentence to make clear that the hyphen relpacement only happens for optional argiments.
1 parent bd13cc0 commit 07327c2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Doc/library/argparse.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -739,9 +739,9 @@ By default, :mod:`!argparse` automatically handles the internal naming and
739739
display names of arguments, simplifying the process without requiring
740740
additional configuration.
741741
As such, you do not need to specify the dest_ and metavar_ parameters.
742-
The dest_ parameter defaults to the argument name with underscores ``_``
743-
replacing hyphens ``-`` . The metavar_ parameter defaults to the
744-
upper-cased name. For example::
742+
The dest_ parameter defaults to the argument name, with underscores ``_``
743+
replacing hyphens ``-`` if the argument is optional . The metavar_
744+
parameter defaults to the upper-cased name. For example::
745745

746746
>>> parser = argparse.ArgumentParser(prog='PROG')
747747
>>> parser.add_argument('--foo-bar')

0 commit comments

Comments
 (0)