MCPcopy Create free account
hub / github.com/ipython/traitlets / getargspec

Function getargspec

traitlets/utils/getargspec.py:19–51  ·  view source on GitHub ↗

Like inspect.getargspec but supports functools.partial as well.

(func: Any)

Source from the content-addressed store, hash-verified

17
18
19def getargspec(func: Any) -> inspect.FullArgSpec:
20 """Like inspect.getargspec but supports functools.partial as well."""
21 if inspect.ismethod(func):
22 func = func.__func__
23 if type(func) is partial:
24 orig_func = func.func
25 argspec = getargspec(orig_func)
26 args = list(argspec[0])
27 defaults = list(argspec[3] or ())
28 kwoargs = list(argspec[4])
29 kwodefs = dict(argspec[5] or {})
30 if func.args:
31 args = args[len(func.args) :]
32 for arg in func.keywords or ():
33 try:
34 i = args.index(arg) - len(args)
35 del args[i]
36 try:
37 del defaults[i]
38 except IndexError:
39 pass
40 except ValueError: # must be a kwonly arg
41 i = kwoargs.index(arg)
42 del kwoargs[i]
43 del kwodefs[arg]
44 return inspect.FullArgSpec(
45 args, argspec[1], argspec[2], tuple(defaults), kwoargs, kwodefs, argspec[6]
46 )
47 while hasattr(func, "__wrapped__"):
48 func = func.__wrapped__
49 if not inspect.isfunction(func):
50 raise TypeError("%r is not a Python function" % func)
51 return inspect.getfullargspec(func)

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…