mirror of https://github.com/flaggo/pydu.git
add doc for inspect.get_func_full_args
This commit is contained in:
parent
8691d4ad9b
commit
ccda1ad515
|
@ -22,6 +22,16 @@ Inspect
|
|||
|
||||
.. py:function:: pydu.inspect.get_func_full_args(func)
|
||||
|
||||
Return a list of (argument name, default value) tuples. If the argument
|
||||
does not have a default value, omit it in the tuple. Arguments such as
|
||||
*args and **kwargs are also included.
|
||||
|
||||
>>> from pydu.inspect import get_func_full_args
|
||||
>>> def f(name, address='home', age=25, *args, **kwargs):
|
||||
... pass
|
||||
...
|
||||
>>> get_func_full_args(f)
|
||||
[('name',), ('address', 'home'), ('age', 25), ('*args',), ('**kwargs',)]
|
||||
|
||||
|
||||
.. py:function:: pydu.inspect.func_accepts_kwargs(func)
|
||||
|
|
|
@ -27,7 +27,10 @@ if PY2:
|
|||
*args and **kwargs are also included.
|
||||
"""
|
||||
argspec = inspect.getargspec(func)
|
||||
args = argspec.args[1:] # ignore 'self'
|
||||
if inspect.ismethod(func):
|
||||
args = argspec.args[1:] # ignore 'self'
|
||||
else:
|
||||
args = argspec.args
|
||||
defaults = argspec.defaults or []
|
||||
# Split args into two lists depending on whether they have default value
|
||||
no_default = args[:len(args) - len(defaults)]
|
||||
|
|
Loading…
Reference in New Issue