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

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork

Reply via email to