2017-11-14 00:27:36 +00:00
|
|
|
Inspect
|
|
|
|
-------
|
|
|
|
|
|
|
|
.. py:function:: pydu.inspect.getargspec(func)
|
2017-11-14 00:44:31 +00:00
|
|
|
|
2017-11-19 02:54:39 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
>>> 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))
|
|
|
|
|
2017-11-14 00:27:36 +00:00
|
|
|
|
|
|
|
.. py:function:: pydu.inspect.get_func_args(func)
|
|
|
|
|
2017-11-19 03:23:33 +00:00
|
|
|
Return a list of the argument names. Arguments such as
|
2017-11-29 00:24:53 +00:00
|
|
|
``*args`` and ``**kwargs`` are not included.
|
2017-11-19 03:23:33 +00:00
|
|
|
|
|
|
|
>>> from pydu.inspect import get_func_args
|
|
|
|
>>> def f(name, address='home', age=25, *args, **kwargs):
|
|
|
|
... pass
|
|
|
|
...
|
|
|
|
>>> get_func_args(f)
|
|
|
|
['name', 'address', 'age']
|
2017-11-14 00:27:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
.. py:function:: pydu.inspect.get_func_full_args(func)
|
|
|
|
|
2017-11-19 02:53:35 +00:00
|
|
|
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
|
2017-11-29 00:24:53 +00:00
|
|
|
``*args`` and ``**kwargs`` are also included.
|
2017-11-19 02:53:35 +00:00
|
|
|
|
|
|
|
>>> 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',)]
|
2017-11-14 00:27:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
.. py:function:: pydu.inspect.func_accepts_kwargs(func)
|
|
|
|
|
2017-11-19 03:23:33 +00:00
|
|
|
Check whether or not the func accepts kwargs.
|
|
|
|
|
|
|
|
>>> from pydu.inspect import func_accepts_kwargs
|
|
|
|
>>> def f(**kwargs):
|
|
|
|
... pass
|
|
|
|
...
|
|
|
|
>>> func_accepts_kwargs(f)
|
|
|
|
True
|
2017-11-14 00:27:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
.. py:function:: pydu.inspect.func_accepts_var_args(func)
|
|
|
|
|
2017-11-19 03:23:33 +00:00
|
|
|
Check whether or not the func accepts var args.
|
|
|
|
|
|
|
|
>>> from pydu.inspect import func_accepts_var_args
|
|
|
|
>>> def f(*vargs):
|
|
|
|
... pass
|
|
|
|
...
|
|
|
|
>>> func_accepts_var_args(f)
|
|
|
|
True
|
|
|
|
|
|
|
|
|
|
|
|
.. py:function:: pydu.inspect.func_supports_parameter(func)
|
|
|
|
|
|
|
|
Check whether or the func supports the given parameter.
|
|
|
|
|
|
|
|
>>> from pydu.inspect import func_supports_parameter
|
|
|
|
>>> def f(name):
|
|
|
|
... pass
|
|
|
|
...
|
|
|
|
>>> func_supports_parameter(f, 'name')
|
|
|
|
True
|
|
|
|
>>> func_supports_parameter(f, 'unkown')
|
|
|
|
Fasle
|
2017-11-14 00:27:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
.. py:function:: pydu.inspect.func_has_no_args(func)
|
|
|
|
|
2017-11-19 03:23:33 +00:00
|
|
|
Check whether or not the func has any args.
|
2017-11-14 00:27:36 +00:00
|
|
|
|
2017-11-19 03:23:33 +00:00
|
|
|
>>> from pydu.inspect import func_has_no_args
|
|
|
|
>>> def f():
|
|
|
|
... pass
|
|
|
|
...
|
|
|
|
>>> func_has_no_args(f)
|
|
|
|
True
|