This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: argparse uses "optional arguments" for "keyword arguments"
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8, Python 3.7, Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: bethard, maggyero, paul.j3, rhettinger
Priority: normal Keywords:

Created on 2019-12-01 14:30 by maggyero, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg357681 - (view) Author: Géry (maggyero) * Date: 2019-12-01 14:30
The argparse module incorrectly uses the terms "optional arguments" for keyword arguments.

For instance this argument parser takes a required keyword argument and an optional positional argument, but classifies the former as an "optional argument" and the latter as a "positional argument":

>>> import argparse
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('--foo', required=True)
_StoreAction(option_strings=['--foo'], dest='foo', nargs=None, const=None, default=None, type=None, choices=None, help=None, metavar=None)
>>> parser.add_argument('bar', nargs='?')
_StoreAction(option_strings=[], dest='bar', nargs='?', const=None, default=None, type=None, choices=None, help=None, metavar=None)
>>> parser.parse_args(['-h'])
usage: [-h] --foo FOO [bar]

positional arguments:
  bar

optional arguments:
  -h, --help  show this help message and exit
  --foo FOO

Since the actual classification seems to distinguish positional from keyword arguments instead of required from optional arguments, I think that the "optional arguments:" section should be renamed to "keyword arguments:".
msg357742 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2019-12-03 05:15
This related to an old issue

https://bugs.python.org/issue9694
argparse required arguments displayed under "optional arguments"

argparse defines two initial argument groups, titled 'positional arguments' and 'optional arguments'.   Alternatives have been suggested, such as 'flagged arguments' and/or 'required arguments'.  But nothing was settled.

Users can define their own argument groups. 

I'd suggest closing this a duplicate, though we can certainly revisit the earlier discussion.
msg357751 - (view) Author: Géry (maggyero) * Date: 2019-12-03 11:18
Thanks paul j3 for the link. I am continuing the discussion there.
History
Date User Action Args
2022-04-11 14:59:23adminsetgithub: 83131
2019-12-03 11:18:05maggyerosetmessages: + msg357751
2019-12-03 06:06:24rhettingersetstatus: open -> closed
resolution: duplicate
stage: resolved
2019-12-03 05:15:48paul.j3setnosy: + paul.j3
messages: + msg357742
2019-12-01 14:30:00maggyerocreate