Author paul.j3
Recipients Arfrever, barry, paul.j3, r.david.murray, ustinov
Date 2013-11-01.07:35:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1383291360.58.0.184292173517.issue19462@psf.upfronthosting.co.za>
In-reply-to
Content
When you add an argument, argparse creates an `Action`, and returns it.  It also places that action in various lists (e.g. parse._actions) and dictionaries.  A `remove_argument` function would have to trace and remove all of those links.  That's a non-trivial task.  However modifying an argument (or Action) is much easier, since there is only one instance.  Obviously some modifications will be safer than others.

For example:

    parser = ArgumentParser()
    a = parser.add_argument('--foo')
    print a

produces:

    _StoreAction(option_strings=['--foo'], dest='foo', nargs=None,    const=None, default=None, type=None, choices=None, help=None, metavar=None)

`vars(a)` gives a somewhat longer list of attributes.  Within reason, those attributes can be changed directly.  I think the 'dest', 'help', 'nargs', 'metavar' could all be changed without hidden effects.  There's also a 'required' attribute that could be changed for optionals.  Changing the 'option_strings' might be problematic, since the parser has a dictionary using those strings as keys.

The constant `argparse.SUPPRESS` is used in several places to alter actions.  For example, to suppress the help, or to suppress default values in the Namespace.  So it might be possible to 'hide' arguments in the subclass, even if you can't remove them.

In http://bugs.python.org/issue14191 I explored a couple of ways of temporarily 'deactivating' certain groups of arguments, so as to parse the optionals and positionals separately.  It's an advance issue, but might still give some ideas. 

Another possibility is to use 'parent' parsers to define clusters of arguments.  Your base class could create a parser with one set of parents, and the subclass could use a different set.
History
Date User Action Args
2013-11-01 07:36:00paul.j3setrecipients: + paul.j3, barry, Arfrever, r.david.murray, ustinov
2013-11-01 07:36:00paul.j3setmessageid: <1383291360.58.0.184292173517.issue19462@psf.upfronthosting.co.za>
2013-11-01 07:36:00paul.j3linkissue19462 messages
2013-11-01 07:35:59paul.j3create