Get information about the arguments accepted by a code object. Three things are returned: (args, varargs, varkw), where 'args' is the list of argument names. Keyword-only arguments are appended. 'varargs' and 'varkw' are the names of the * and ** arguments or None.
(co)
| 1202 | Arguments = namedtuple('Arguments', 'args, varargs, varkw') |
| 1203 | |
| 1204 | def getargs(co): |
| 1205 | """Get information about the arguments accepted by a code object. |
| 1206 | |
| 1207 | Three things are returned: (args, varargs, varkw), where |
| 1208 | 'args' is the list of argument names. Keyword-only arguments are |
| 1209 | appended. 'varargs' and 'varkw' are the names of the * and ** |
| 1210 | arguments or None.""" |
| 1211 | if not iscode(co): |
| 1212 | raise TypeError('{!r} is not a code object'.format(co)) |
| 1213 | |
| 1214 | names = co.co_varnames |
| 1215 | nargs = co.co_argcount |
| 1216 | nkwargs = co.co_kwonlyargcount |
| 1217 | args = list(names[:nargs]) |
| 1218 | kwonlyargs = list(names[nargs:nargs+nkwargs]) |
| 1219 | |
| 1220 | nargs += nkwargs |
| 1221 | varargs = None |
| 1222 | if co.co_flags & CO_VARARGS: |
| 1223 | varargs = co.co_varnames[nargs] |
| 1224 | nargs = nargs + 1 |
| 1225 | varkw = None |
| 1226 | if co.co_flags & CO_VARKEYWORDS: |
| 1227 | varkw = co.co_varnames[nargs] |
| 1228 | return Arguments(args + kwonlyargs, varargs, varkw) |
| 1229 | |
| 1230 | |
| 1231 | FullArgSpec = namedtuple('FullArgSpec', |
no test coverage detected