MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / getcallargs

Function getcallargs

tensorflow/python/util/tf_inspect.py:260–294  ·  view source on GitHub ↗

TFDecorator-aware replacement for inspect.getcallargs. Args: *func_and_positional: A callable, possibly decorated, followed by any positional arguments that would be passed to `func`. **named: The named argument dictionary that would be passed to `func`. Returns: A dictionary

(*func_and_positional, **named)

Source from the content-addressed store, hash-verified

258
259
260def getcallargs(*func_and_positional, **named):
261 """TFDecorator-aware replacement for inspect.getcallargs.
262
263 Args:
264 *func_and_positional: A callable, possibly decorated, followed by any
265 positional arguments that would be passed to `func`.
266 **named: The named argument dictionary that would be passed to `func`.
267
268 Returns:
269 A dictionary mapping `func`'s named arguments to the values they would
270 receive if `func(*positional, **named)` were called.
271
272 `getcallargs` will use the argspec from the outermost decorator that provides
273 it. If no attached decorators modify argspec, the final unwrapped target's
274 argspec will be used.
275 """
276 func = func_and_positional[0]
277 positional = func_and_positional[1:]
278 argspec = getfullargspec(func)
279 call_args = named.copy()
280 this = getattr(func, 'im_self', None) or getattr(func, '__self__', None)
281 if ismethod(func) and this:
282 positional = (this,) + positional
283 remaining_positionals = [arg for arg in argspec.args if arg not in call_args]
284 call_args.update(dict(zip(remaining_positionals, positional)))
285 default_count = 0 if not argspec.defaults else len(argspec.defaults)
286 if default_count:
287 for arg, value in zip(argspec.args[-default_count:], argspec.defaults):
288 if arg not in call_args:
289 call_args[arg] = value
290 if argspec.kwonlydefaults is not None:
291 for k, v in argspec.kwonlydefaults.items():
292 if k not in call_args:
293 call_args[k] = v
294 return call_args
295
296
297def getframeinfo(*args, **kwargs):

Callers

nothing calls this directly

Calls 4

getfullargspecFunction · 0.85
ismethodFunction · 0.85
copyMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected