mirror of https://github.com/flaggo/pydu.git
fix get_func_args error and update the doc
This commit is contained in:
parent
ccda1ad515
commit
7b38d15cdc
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue