MCPcopy Create free account
hub / github.com/numpy/numpy / getargs

Function getargs

numpy/_utils/_inspect.py:65–94  ·  view source on GitHub ↗

Get information about the arguments accepted by a code object. Three things are returned: (args, varargs, varkw), where 'args' is a list of argument names (possibly containing nested lists), and 'varargs' and 'varkw' are the names of the * and ** arguments or None.

(co)

Source from the content-addressed store, hash-verified

63CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS = 1, 2, 4, 8
64
65def getargs(co):
66 """Get information about the arguments accepted by a code object.
67
68 Three things are returned: (args, varargs, varkw), where 'args' is
69 a list of argument names (possibly containing nested lists), and
70 'varargs' and 'varkw' are the names of the * and ** arguments or None.
71
72 """
73
74 if not iscode(co):
75 raise TypeError('arg is not a code object')
76
77 nargs = co.co_argcount
78 names = co.co_varnames
79 args = list(names[:nargs])
80
81 # The following acrobatics are for anonymous (tuple) arguments.
82 # Which we do not need to support, so remove to avoid importing
83 # the dis module.
84 for i in range(nargs):
85 if args[i][:1] in ['', '.']:
86 raise TypeError("tuple function arguments are not supported")
87 varargs = None
88 if co.co_flags & CO_VARARGS:
89 varargs = co.co_varnames[nargs]
90 nargs = nargs + 1
91 varkw = None
92 if co.co_flags & CO_VARKEYWORDS:
93 varkw = co.co_varnames[nargs]
94 return args, varargs, varkw
95
96def getargspec(func):
97 """Get the names and default values of a function's arguments.

Callers 2

getargspecFunction · 0.70
getargvaluesFunction · 0.70

Calls 1

iscodeFunction · 0.85

Tested by

no test coverage detected