Author paul.j3
Recipients BreamoreBoy, bethard, jnothman, paul.j3
Date 2014-07-12.22:22:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1405203755.32.0.34936549167.issue16516@psf.upfronthosting.co.za>
In-reply-to
Content
This is a straight forward patch, modifying '_registry_get' to return 'default' if it gets this 'TypeError'.  'test_argparse.py' has a testcase based on jnothman's example.  Temporarily it includes a skipped test that would pass the original code.

The alternative would be to add a note to the documentation to the effect that the 'type' must also be hashable.  But for an edge condition like this, that may be more confusing than enlightening.

While 'dict(one=1, two=20).get' now works as a 'type' callable, it is not ideal.  If there is no match it returns None.  The alternative '.__getitem__' raises a KeyError.  But '_get_values' handles TypeError and ValueErrors, the kinds returned by 'int' and 'float'.  It also handles an ArgumentTypeError, giving a custom type more control over the error message.  Is it worth noting something about the type errors in the documentation?

I've seen users make a different error with the type parameter - 'type=boolean', thinking this means the input should be converted to boolean.  They are thinking of 'type' as a datatype, rather than a function that converts a string into something else.  I don't know of a solution other than explaining that 'boolean()' does not act like 'int()'.

This patch also handles the 'action' case.  However I can't think of a way write a Action subclass that would be unhashable.  It would have to inherit from both Action and dict.
History
Date User Action Args
2014-07-12 22:22:35paul.j3setrecipients: + paul.j3, bethard, BreamoreBoy, jnothman
2014-07-12 22:22:35paul.j3setmessageid: <1405203755.32.0.34936549167.issue16516@psf.upfronthosting.co.za>
2014-07-12 22:22:35paul.j3linkissue16516 messages
2014-07-12 22:22:34paul.j3create