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.

Title: argparse remove subparser
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Rosuav, bethard, biko, paul.j3, tshepang
Priority: normal Keywords: patch

Created on 2013-08-17 16:30 by biko, last changed 2022-04-11 14:57 by admin.

File name Uploaded Description Edit
argparse_remove_parser.patch biko, 2013-08-17 16:30 review
Messages (5)
msg195494 - (view) Author: Michael Bikovitsky (biko) Date: 2013-08-17 16:30
It might be useful in some circumstances to be able to remove a subparser, however the module does not provide such functionality.

The proposed method takes the same arguments as the add_parser method and removes the matching subparser from the map (including aliases).
msg224646 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-08-03 16:41
@Paul it's a simple enough patch, what do you think?
msg252767 - (view) Author: Chris Angelico (Rosuav) * Date: 2015-10-11 05:50
Patch applies cleanly to 3.6 and doesn't appear to add any new test failures (3.6 currently has a couple). Needs its own test, though.
msg252832 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2015-10-11 23:52
Under what circumstances would this be useful? asks for a 'remove_argument' method.  That seems to be most useful if the argument is inherited from a parent parser.

A subparsers argument could be inherited from a parent (I think), but the parenting mechanism does not provide a reference to the corresponding  _SubParsersAction object.  We'd have to look it up in the main parser._actions.

Also parenting does not make copies of the Actions.  It just copies references.  That means any change to the main parser  _SubParsersAction object is also a change to the parent's object. discusses the problems involved changing an inherited argument.

The method seems simple enough, but I'd like to see a better case for its value.
msg252891 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2015-10-12 21:33
There's a partial overlap with this issue

which seeks to hide a subparser - both in the help lines and the choices lists.
Date User Action Args
2022-04-11 14:57:49adminsetgithub: 62969
2019-02-24 22:24:18BreamoreBoysetnosy: - BreamoreBoy
2015-10-12 21:33:01paul.j3setmessages: + msg252891
2015-10-11 23:52:41paul.j3setmessages: + msg252832
2015-10-11 22:41:15paul.j3setnosy: + paul.j3
2015-10-11 05:50:47Rosuavsetnosy: + Rosuav

messages: + msg252767
versions: + Python 3.6, - Python 3.5
2014-08-03 16:41:35BreamoreBoysetnosy: + BreamoreBoy

messages: + msg224646
versions: + Python 3.5, - Python 3.4
2013-08-23 16:42:34tshepangsetnosy: + tshepang
2013-08-17 16:30:40bikocreate