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)
| 1299 | Arguments = namedtuple('Arguments', 'args, varargs, varkw') |
| 1300 | |
| 1301 | def getargs(co): |
| 1302 | """Get information about the arguments accepted by a code object. |
| 1303 | |
| 1304 | Three things are returned: (args, varargs, varkw), where |
| 1305 | 'args' is the list of argument names. Keyword-only arguments are |
| 1306 | appended. 'varargs' and 'varkw' are the names of the * and ** |
| 1307 | arguments or None.""" |
| 1308 | if not iscode(co): |
| 1309 | raise TypeError('{!r} is not a code object'.format(co)) |
| 1310 | |
| 1311 | names = co.co_varnames |
| 1312 | nargs = co.co_argcount |
| 1313 | nkwargs = co.co_kwonlyargcount |
| 1314 | args = list(names[:nargs]) |
| 1315 | kwonlyargs = list(names[nargs:nargs+nkwargs]) |
| 1316 | step = 0 |
| 1317 | |
| 1318 | nargs += nkwargs |
| 1319 | varargs = None |
| 1320 | if co.co_flags & CO_VARARGS: |
| 1321 | varargs = co.co_varnames[nargs] |
| 1322 | nargs = nargs + 1 |
| 1323 | varkw = None |
| 1324 | if co.co_flags & CO_VARKEYWORDS: |
| 1325 | varkw = co.co_varnames[nargs] |
| 1326 | return Arguments(args + kwonlyargs, varargs, varkw) |
| 1327 | |
| 1328 | |
| 1329 | FullArgSpec = namedtuple('FullArgSpec', |
no test coverage detected