diff options
author | steven.bethard <devnull@localhost> | 2010-02-28 08:37:14 +0000 |
---|---|---|
committer | steven.bethard <devnull@localhost> | 2010-02-28 08:37:14 +0000 |
commit | 3be7b3eb9fc55ddad0a5950602deabcff5f046d9 (patch) | |
tree | 064cf4da25c2d9930963c9dad7205fa00c1f8d6d /argparse.py | |
parent | f34cf60cfcb22c8929543411c15fe662849e4a6a (diff) | |
download | argparse-3be7b3eb9fc55ddad0a5950602deabcff5f046d9.tar.gz |
Better error messages for errors like type='int'. This actually caught a bug in one of the tests and as I result, this patch also makes sure that types display as their type name when %(type)s is specified.
Diffstat (limited to 'argparse.py')
-rw-r--r-- | argparse.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/argparse.py b/argparse.py index c89618b..4966b14 100644 --- a/argparse.py +++ b/argparse.py @@ -621,6 +621,9 @@ class HelpFormatter(object): for name in list(params): if params[name] is SUPPRESS: del params[name] + for name in list(params): + if hasattr(params[name], '__name__'): + params[name] = params[name].__name__ if params.get('choices') is not None: choices_str = ', '.join([str(c) for c in params['choices']]) params['choices'] = choices_str @@ -1297,6 +1300,12 @@ class _ActionsContainer(object): if not _callable(action_class): raise ValueError('unknown action "%s"' % action_class) action = action_class(**kwargs) + + # raise an error if the action type is not callable + type_func = self._registry_get('type', action.type, action.type) + if not _callable(type_func): + raise ValueError('%r is not callable' % type_func) + return self._add_action(action) def add_argument_group(self, *args, **kwargs): |