Bug in user defined argument type error message #45

Merged
merged 1 commit into from Feb 4, 2013

Conversation

Projects
None yet
2 participants
Contributor

hpaulj commented Jan 30, 2013

If a user defined argument type function throws an error, the resulting error message includes the whole function .toString(), not just the function's name.

I modified the ArgumentParser._getValue() error message generator to test whether the action.type is a string (i.e. a registered type). If not, it is a function. It tries to deduce the function name (type.name), or looks for a type.displayName value (user defined). If nothing can be found, use <function> (analogous to the <lambda> that Python displays), and attach the original error message.

test/user_defined_type.js - mocha tests for action.type, including several user defined cases. Some are taken from test_argparse.py, some focus on the bug discussed here.

Bug: with a user defined argument type, an error displays
the whole function code, rather than just its name.

Modify the ArgumentParser._getValue() error message generator to test
whether action.type is a string (registered type).  If not, it is a
function.  Try to deduce its name (type.name), or type.displayName (a
user defined name).  If there is no name (an anonymous function), include
the original error message in the displayed error.

test/user_defined_type.js - mocha tests for action.type, including several
user defined cases.  Some are taken from test_argparse.py, some focus on
the bug discussed here.

In the Python, all functions have a .__name__, which it uses in the error
message.  For lambda functions that name is just <lambda>

shkuropat added a commit that referenced this pull request Feb 4, 2013

Merge pull request #45 from hpaulj/user_type
Bug in user defined argument type error message

@shkuropat shkuropat merged commit cf4a2e0 into nodeca:master Feb 4, 2013

Collaborator

shkuropat commented Feb 4, 2013

Thanks.

@hpaulj hpaulj referenced this pull request Feb 20, 2013

Open

ArgumentTypeError #50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment