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 charlie.proctor, paul.j3, rrt
Date 2016-11-07.01:00:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1478480415.47.0.991180559955.issue28609@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016-11-07 01:00:15paul.j3setrecipients: + paul.j3, charlie.proctor, rrt
2016-11-07 01:00:15paul.j3setmessageid: <1478480415.47.0.991180559955.issue28609@psf.upfronthosting.co.za>
2016-11-07 01:00:15paul.j3linkissue28609 messages
2016-11-07 01:00:15paul.j3create