Message280180
Simply including a `default` parameter, even with the default default None, changes the error message
In [395]: parser=argparse.ArgumentParser()
In [396]: parser.add_argument('cmd');
In [397]: a=parser.add_argument('args',nargs='*',default=None)
In [398]: a.required
Out[398]: False
In [399]: parser.parse_args([])
usage: ipython3 [-h] cmd [args [args ...]]
ipython3: error: the following arguments are required: cmd
You shouldn't see any other changes in behavior (except maybe if the positional is in a mutually_exclusive_group). The code that sets 'required' for positionals only looks for the presence of the parameter in kwargs, not its value: `'default' not in kwargs`.
An alternative is to change the value of 'required' after creation:
a.required = False
Anyways I remain convinced that changing the 'required' attribute is the correct way to change the error message, not adding more tests to the message generator. |
|
Date |
User |
Action |
Args |
2016-11-07 01:00:15 | paul.j3 | set | recipients:
+ paul.j3, charlie.proctor, rrt |
2016-11-07 01:00:15 | paul.j3 | set | messageid: <1478480415.47.0.991180559955.issue28609@psf.upfronthosting.co.za> |
2016-11-07 01:00:15 | paul.j3 | link | issue28609 messages |
2016-11-07 01:00:15 | paul.j3 | create | |
|