From 7b38d15cdcf0804432e366e0a911acf89de8e54d Mon Sep 17 00:00:00 2001 From: Prodesire Date: Sun, 19 Nov 2017 10:54:39 +0800 Subject: [PATCH] fix get_func_args error and update the doc --- docs/inspect.rst | 22 ++++++++++++---------- pydu/inspect.py | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/docs/inspect.rst b/docs/inspect.rst index 09fbe99..a787308 100644 --- a/docs/inspect.rst +++ b/docs/inspect.rst @@ -3,18 +3,20 @@ Inspect .. py:function:: pydu.inspect.getargspec(func) - Get the names and default values of a function's arguments. + Get the names and default values of a function's arguments. - A tuple of four things is returned: (args, varargs, varkw, defaults). - ``args`` is a list of the argument names (it may contain nested lists). - ``varargs`` and ``varkw`` are the names of the * and ** arguments or None. - ``defaults`` is an n-tuple of the default values of the last n arguments. + A tuple of four things is returned: (args, varargs, varkw, defaults). + ``args`` is a list of the argument names (it may contain nested lists). + ``varargs`` and ``varkw`` are the names of the * and ** arguments or None. + ``defaults`` is an n-tuple of the default values of the last n arguments. + + >>> from pydu.inspect import getargspec + >>> def f(name, address='home', age=25, *args, **kwargs): + ... pass + ... + >>> getargspect(f) + ArgSpec(args=['name', 'address', 'age'], varargs='args', keywords='kwargs', defaults=('home', 25)) - >>> from pydu.inspect import getargspec - >>> def f(a, b=1, *c, **d): - ... pass - >>> getargspect(f) - ArgSpec(args=['a', 'b'], varargs='c', keywords='d', defaults=(1,)) .. py:function:: pydu.inspect.get_func_args(func) diff --git a/pydu/inspect.py b/pydu/inspect.py index e277aa1..066354c 100644 --- a/pydu/inspect.py +++ b/pydu/inspect.py @@ -16,7 +16,7 @@ if PY2: def get_func_args(func): argspec = inspect.getargspec(func) if inspect.ismethod(func): - return argspec[1:] # ignore 'self' + return argspec.args[1:] # ignore 'self' return argspec.args