paul j3 added the comment:
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.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue28609>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com