pwclient handling of argparse options

Mike Frysinger vapier at gentoo.org
Tue Oct 20 04:56:35 AEDT 2015


On 19 Oct 2015 09:57, Bernhard Reutner-Fischer wrote:
> On October 17, 2015 4:25:54 AM GMT+02:00, Mike Frysinger wrote:
> >On 16 Oct 2015 16:39, Brian Norris wrote:
> >>          commit_str = args.get('c')
> >
> >if you feel like cleaning things up, i find the args behavior weird and
> >non-standard.  it does:
> >	args = action_parser.parse_args()
> >	args = dict(vars(args))
> >	action = args.get('subcmd')
> >
> >normally argparse code does:
> >	args = action_parser.parse_args()
> >	action = args.subcmd
> >
> >i'm not sure why this dict/get style was picked.  maybe Bernhard can
> >shed some light here.
> 
> At this point all we need is a dict and I found it easier and shorter to type.

i'm not sure how this is shorter:
	args.get('subcmd')
than this:
	args.subcmd

it's also more dangerous: get will not throw an error if the key
doesn't exist.  so if you did something like:
	args.get('submcd')
you might not notice -- python would return None in the default case
you didn't typo and everytime you typod.  but if you did:
	args.submcd
then python would an exception as soon as that code is run.  since
argparse has a default=None, args.subcmd would return None if the
user hadn't specified anything.

> I do remember to have gone through hoops to handle --help and --hash at the same time AND allowing for recursive printing of all help (I considered that a feature back then) but I do not remember if or why my attempt to use a conflict_handler didn't work out. Could be there was a bug in argparse back then or maybe I just goofed it.

Brian has posted some CLs to clean that up by using some more of the
argparse infrastructure.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.ozlabs.org/pipermail/patchwork/attachments/20151019/a9d85a7b/attachment-0001.sig>


More information about the Patchwork mailing list