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 subcommand docs has non-existent parameter "action"
Type: behavior Stage: resolved
Components: Documentation 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: docs@python Nosy List: docs@python, paul.j3, retnikt, xtreak
Priority: normal Keywords:

Created on 2019-07-30 07:44 by retnikt, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg348718 - (view) Author: retnikt (retnikt) Date: 2019-07-30 07:44
In the library documentation for argparse, the section for ArgumentParser.add_subparsers ( https://docs.python.org/3/library/argparse.html#sub-commands ) states that there is a parameter for 'action' with the description 'the basic type of action to be taken when this argument is encountered at the command line'. However, no such parameter actually exists, and passing it to the function causes very strange behaviour:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/argparse.py", line 1716, in add_subparsers
    action = parsers_class(option_strings=[], **kwargs)
TypeError: __init__() got an unexpected keyword argument 'parser_class'

This line should be removed from the documentation. It is present in versions 3.4+ and 2.7
msg348721 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-07-30 08:37
Seems related : issue23487 . kwargs is manipulated before passing to parsers_class causing the error message and also the discussion in issue23487 notes this to be a documentation issue over usage of action argument.
msg348761 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2019-07-30 17:28
As discussed in https://bugs.python.org/issue23487, `action` works if the class is compatible with argparse._SubParsersAction.

these commands all do the same thing:

    parser.add_subparsers()       # default
    parser.add_subparsers(action='parsers')  
    parser.add_subparsers(action=argparse._SubParsersAction) 

Your example using 

    parser.add_subparsers(action='store')

raises the error because the argparse._StoreAction class cannot handle the `parser_class` parameter that add_subparsers has added to the kwargs.
msg383409 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2020-12-19 23:08
I'm closing the is as a duplicate of https://bugs.python.org/issue23487, which is already closed.
History
Date User Action Args
2022-04-11 14:59:18adminsetgithub: 81898
2020-12-19 23:08:59paul.j3setstatus: open -> closed
resolution: duplicate
messages: + msg383409

stage: resolved
2019-07-30 17:28:04paul.j3setmessages: + msg348761
2019-07-30 08:37:30xtreaksetnosy: + xtreak
messages: + msg348721
2019-07-30 08:10:56xtreaksetnosy: + paul.j3
2019-07-30 07:44:41retniktcreate