Fully vendored version of getfullargspec from Python 3.3.
(func: Callable[..., Any])
| 172 | |
| 173 | |
| 174 | def inspect_getfullargspec(func: Callable[..., Any]) -> FullArgSpec: |
| 175 | """Fully vendored version of getfullargspec from Python 3.3.""" |
| 176 | |
| 177 | if inspect.ismethod(func): |
| 178 | func = func.__func__ |
| 179 | if not inspect.isfunction(func) and not hasattr(func, "__code__"): |
| 180 | raise TypeError(f"{func!r} is not a Python function") |
| 181 | |
| 182 | co = func.__code__ |
| 183 | if not inspect.iscode(co): |
| 184 | raise TypeError(f"{co!r} is not a code object") |
| 185 | |
| 186 | nargs = co.co_argcount |
| 187 | names = co.co_varnames |
| 188 | nkwargs = co.co_kwonlyargcount |
| 189 | args = list(names[:nargs]) |
| 190 | kwonlyargs = list(names[nargs : nargs + nkwargs]) |
| 191 | |
| 192 | nargs += nkwargs |
| 193 | varargs = None |
| 194 | if co.co_flags & inspect.CO_VARARGS: |
| 195 | varargs = co.co_varnames[nargs] |
| 196 | nargs = nargs + 1 |
| 197 | varkw = None |
| 198 | if co.co_flags & inspect.CO_VARKEYWORDS: |
| 199 | varkw = co.co_varnames[nargs] |
| 200 | |
| 201 | return FullArgSpec( |
| 202 | args, |
| 203 | varargs, |
| 204 | varkw, |
| 205 | func.__defaults__, |
| 206 | kwonlyargs, |
| 207 | func.__kwdefaults__, |
| 208 | get_annotations(func), |
| 209 | ) |
| 210 | |
| 211 | |
| 212 | if py39: |