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)
| 1226 | Arguments = namedtuple('Arguments', 'args, varargs, varkw') |
| 1227 | |
| 1228 | def getargs(co): |
| 1229 | """Get information about the arguments accepted by a code object. |
| 1230 | |
| 1231 | Three things are returned: (args, varargs, varkw), where |
| 1232 | 'args' is the list of argument names. Keyword-only arguments are |
| 1233 | appended. 'varargs' and 'varkw' are the names of the * and ** |
| 1234 | arguments or None.""" |
| 1235 | if not iscode(co): |
| 1236 | raise TypeError('{!r} is not a code object'.format(co)) |
| 1237 | |
| 1238 | names = co.co_varnames |
| 1239 | nargs = co.co_argcount |
| 1240 | nkwargs = co.co_kwonlyargcount |
| 1241 | args = list(names[:nargs]) |
| 1242 | kwonlyargs = list(names[nargs:nargs+nkwargs]) |
| 1243 | |
| 1244 | nargs += nkwargs |
| 1245 | varargs = None |
| 1246 | if co.co_flags & CO_VARARGS: |
| 1247 | varargs = co.co_varnames[nargs] |
| 1248 | nargs = nargs + 1 |
| 1249 | varkw = None |
| 1250 | if co.co_flags & CO_VARKEYWORDS: |
| 1251 | varkw = co.co_varnames[nargs] |
| 1252 | return Arguments(args + kwonlyargs, varargs, varkw) |
| 1253 | |
| 1254 | |
| 1255 | FullArgSpec = namedtuple('FullArgSpec', |
no test coverage detected
searching dependent graphs…