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.

Author paul.j3
Recipients jzwinck, paul.j3
Date 2014-05-28.21:29:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1401312588.73.0.687668039207.issue20430@psf.upfronthosting.co.za>
In-reply-to
Content
In the attached file I tried another approach - a custom Action class.  It gives you the custom behavior now, instead of 2-3 releases in the future.

    class Action2(Action):
        # custom action
        def __init__(self, *args, **kwargs):
            super(Action2, self).__init__(*args, **kwargs)
            self.default = SUPPRESS 
        def __call__(self, parser, namespace, values, option_string=None):
           print('Action2', argparse._get_action_name(self), values)

'self.default=SUPPRESS' keeps the dest out of the namespace without affecting help display.  And as with '_HelpAction', the __call__ can do its own thing without modifying the namespace.

One thing that this custom Action class does not do well is let you modify the handling of the argument after it is created.  For example if an argument is created by an imported parent parser, attributes like 'dest' and 'default' can be changed after the fact, but the argument class can't.

In   http://bugs.python.org/issue14191  I wrestled with the issue of temporarily disabling subsets of the arguments, first the positionals, and then the optionals, so I could run 'parse_known_args' separately on the two groups.

For optionals it was enough to ensure that 'required=False'.  For positionals I first used 'nargs=0', and latter enabled a 'nargs=SUPPRESS' option to suppress them.
History
Date User Action Args
2014-05-28 21:29:48paul.j3setrecipients: + paul.j3, jzwinck
2014-05-28 21:29:48paul.j3setmessageid: <1401312588.73.0.687668039207.issue20430@psf.upfronthosting.co.za>
2014-05-28 21:29:48paul.j3linkissue20430 messages
2014-05-28 21:29:48paul.j3create