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' i
(obj)
| 18 | # Note: copied from OInspect, kept here so the testing stuff doesn't create |
| 19 | # circular dependencies and is easier to reuse. |
| 20 | def getargspec(obj): |
| 21 | """Get the names and default values of a function's arguments. |
| 22 | |
| 23 | A tuple of four things is returned: (args, varargs, varkw, defaults). |
| 24 | 'args' is a list of the argument names (it may contain nested lists). |
| 25 | 'varargs' and 'varkw' are the names of the * and ** arguments or None. |
| 26 | 'defaults' is an n-tuple of the default values of the last n arguments. |
| 27 | |
| 28 | Modified version of inspect.getargspec from the Python Standard |
| 29 | Library.""" |
| 30 | |
| 31 | if inspect.isfunction(obj): |
| 32 | func_obj = obj |
| 33 | elif inspect.ismethod(obj): |
| 34 | func_obj = obj.__func__ |
| 35 | else: |
| 36 | raise TypeError('arg is not a Python function') |
| 37 | args, varargs, varkw = inspect.getargs(func_obj.__code__) |
| 38 | return args, varargs, varkw, func_obj.__defaults__ |
| 39 | |
| 40 | #----------------------------------------------------------------------------- |
| 41 | # Testing functions |
no outgoing calls
no test coverage detected