Fully vendored version of getfullargspec from Python 3.3.
(func: Callable[..., Any])
| 96 | |
| 97 | |
| 98 | def inspect_getfullargspec(func: Callable[..., Any]) -> FullArgSpec: |
| 99 | """Fully vendored version of getfullargspec from Python 3.3.""" |
| 100 | |
| 101 | if inspect.ismethod(func): |
| 102 | func = func.__func__ |
| 103 | if not inspect.isfunction(func) and not hasattr(func, "__code__"): |
| 104 | raise TypeError(f"{func!r} is not a Python function") |
| 105 | |
| 106 | co = func.__code__ |
| 107 | if not inspect.iscode(co): |
| 108 | raise TypeError(f"{co!r} is not a code object") |
| 109 | |
| 110 | nargs = co.co_argcount |
| 111 | names = co.co_varnames |
| 112 | nkwargs = co.co_kwonlyargcount |
| 113 | args = list(names[:nargs]) |
| 114 | kwonlyargs = list(names[nargs : nargs + nkwargs]) |
| 115 | |
| 116 | nargs += nkwargs |
| 117 | varargs = None |
| 118 | if co.co_flags & inspect.CO_VARARGS: |
| 119 | varargs = co.co_varnames[nargs] |
| 120 | nargs = nargs + 1 |
| 121 | varkw = None |
| 122 | if co.co_flags & inspect.CO_VARKEYWORDS: |
| 123 | varkw = co.co_varnames[nargs] |
| 124 | |
| 125 | return FullArgSpec( |
| 126 | args, |
| 127 | varargs, |
| 128 | varkw, |
| 129 | func.__defaults__, |
| 130 | kwonlyargs, |
| 131 | func.__kwdefaults__, |
| 132 | get_annotations(func), |
| 133 | ) |
| 134 | |
| 135 | |
| 136 | # python stubs don't have a public type for this. not worth |