[issue37717] argparse subcommand docs has non-existent parameter "action"

New submission from retnikt <retnikt@gmail.com>: 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 ---------- assignee: docs@python components: Documentation messages: 348718 nosy: docs@python, retnikt priority: normal severity: normal status: open title: argparse subcommand docs has non-existent parameter "action" type: behavior versions: Python 2.7, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue37717> _______________________________________

Change by Karthikeyan Singaravelan <tir.karthi@gmail.com>: ---------- nosy: +paul.j3 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue37717> _______________________________________

Karthikeyan Singaravelan <tir.karthi@gmail.com> added the comment: 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. ---------- nosy: +xtreak _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue37717> _______________________________________

paul j3 <ajipanca@gmail.com> added the comment: 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. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue37717> _______________________________________

paul j3 <ajipanca@gmail.com> added the comment: I'm closing the is as a duplicate of https://bugs.python.org/issue23487, which is already closed. ---------- resolution: -> duplicate stage: -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue37717> _______________________________________
participants (3)
-
Karthikeyan Singaravelan
-
paul j3
-
retnikt