refine code, make compatible between 2 and 3
@@ -40,13 +40,14 @@ class _ArgumentParser(object):
class PythonArgumentParser(_ArgumentParser):
def _get_arg_spec(self, handler):
- args_tuple = inspect.getfullargspec(handler)
+ if sys.version_info[0] == 2:
+ args, varargs, kwargs, defaults = inspect.getargspec(handler)
+ elif sys.version_info[0] == 3:
+ args, varargs, varkw, defaults, _, _, _ = inspect.getfullargspec(handler)
if inspect.ismethod(handler) or handler.__name__ == '__init__':
- args = args_tuple.args[1:] # drop 'self'
- else:
- args = args_tuple.args
- defaults = list(args_tuple.defaults) if args_tuple.defaults else []
- return args, defaults, args_tuple.varargs, args_tuple.varkw
+ args = args[1:] # drop 'self'
+ defaults = list(defaults) if defaults else []
+ return args, defaults, varargs, varkw
class JavaArgumentParser(_ArgumentParser):
