Get the names and default values of a callable object's parameters. A tuple of seven things is returned: (args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations). 'args' is a list of the parameter names. 'varargs' and 'varkw' are the names of the * and ** parameters
(func)
| 1232 | 'args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations') |
| 1233 | |
| 1234 | def getfullargspec(func): |
| 1235 | """Get the names and default values of a callable object's parameters. |
| 1236 | |
| 1237 | A tuple of seven things is returned: |
| 1238 | (args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations). |
| 1239 | 'args' is a list of the parameter names. |
| 1240 | 'varargs' and 'varkw' are the names of the * and ** parameters or None. |
| 1241 | 'defaults' is an n-tuple of the default values of the last n parameters. |
| 1242 | 'kwonlyargs' is a list of keyword-only parameter names. |
| 1243 | 'kwonlydefaults' is a dictionary mapping names from kwonlyargs to defaults. |
| 1244 | 'annotations' is a dictionary mapping parameter names to annotations. |
| 1245 | |
| 1246 | Notable differences from inspect.signature(): |
| 1247 | - the "self" parameter is always reported, even for bound methods |
| 1248 | - wrapper chains defined by __wrapped__ *not* unwrapped automatically |
| 1249 | """ |
| 1250 | try: |
| 1251 | # Re: `skip_bound_arg=False` |
| 1252 | # |
| 1253 | # There is a notable difference in behaviour between getfullargspec |
| 1254 | # and Signature: the former always returns 'self' parameter for bound |
| 1255 | # methods, whereas the Signature always shows the actual calling |
| 1256 | # signature of the passed object. |
| 1257 | # |
| 1258 | # To simulate this behaviour, we "unbind" bound methods, to trick |
| 1259 | # inspect.signature to always return their first parameter ("self", |
| 1260 | # usually) |
| 1261 | |
| 1262 | # Re: `follow_wrapper_chains=False` |
| 1263 | # |
| 1264 | # getfullargspec() historically ignored __wrapped__ attributes, |
| 1265 | # so we ensure that remains the case in 3.3+ |
| 1266 | |
| 1267 | sig = _signature_from_callable(func, |
| 1268 | follow_wrapper_chains=False, |
| 1269 | skip_bound_arg=False, |
| 1270 | sigcls=Signature, |
| 1271 | eval_str=False) |
| 1272 | except Exception as ex: |
| 1273 | # Most of the times 'signature' will raise ValueError. |
| 1274 | # But, it can also raise AttributeError, and, maybe something |
| 1275 | # else. So to be fully backwards compatible, we catch all |
| 1276 | # possible exceptions here, and reraise a TypeError. |
| 1277 | raise TypeError('unsupported callable') from ex |
| 1278 | |
| 1279 | args = [] |
| 1280 | varargs = None |
| 1281 | varkw = None |
| 1282 | posonlyargs = [] |
| 1283 | kwonlyargs = [] |
| 1284 | annotations = {} |
| 1285 | defaults = () |
| 1286 | kwdefaults = {} |
| 1287 | |
| 1288 | if sig.return_annotation is not sig.empty: |
| 1289 | annotations['return'] = sig.return_annotation |
| 1290 | |
| 1291 | for param in sig.parameters.values(): |
no test coverage detected