MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / getcallargs

Function getcallargs

tools/python-3.11.9-amd64/Lib/inspect.py:1518–1576  ·  view source on GitHub ↗

Get the mapping of arguments to values. A dict is returned, with keys the function argument names (including the names of the * and ** arguments, if any), and values the respective bound values from 'positional' and 'named'.

(func, /, *positional, **named)

Source from the content-addressed store, hash-verified

1516 "was" if given == 1 and not kwonly_given else "were"))
1517
1518def getcallargs(func, /, *positional, **named):
1519 """Get the mapping of arguments to values.
1520
1521 A dict is returned, with keys the function argument names (including the
1522 names of the * and ** arguments, if any), and values the respective bound
1523 values from 'positional' and 'named'."""
1524 spec = getfullargspec(func)
1525 args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = spec
1526 f_name = func.__name__
1527 arg2value = {}
1528
1529
1530 if ismethod(func) and func.__self__ is not None:
1531 # implicit 'self' (or 'cls' for classmethods) argument
1532 positional = (func.__self__,) + positional
1533 num_pos = len(positional)
1534 num_args = len(args)
1535 num_defaults = len(defaults) if defaults else 0
1536
1537 n = min(num_pos, num_args)
1538 for i in range(n):
1539 arg2value[args[i]] = positional[i]
1540 if varargs:
1541 arg2value[varargs] = tuple(positional[n:])
1542 possible_kwargs = set(args + kwonlyargs)
1543 if varkw:
1544 arg2value[varkw] = {}
1545 for kw, value in named.items():
1546 if kw not in possible_kwargs:
1547 if not varkw:
1548 raise TypeError("%s() got an unexpected keyword argument %r" %
1549 (f_name, kw))
1550 arg2value[varkw][kw] = value
1551 continue
1552 if kw in arg2value:
1553 raise TypeError("%s() got multiple values for argument %r" %
1554 (f_name, kw))
1555 arg2value[kw] = value
1556 if num_pos > num_args and not varargs:
1557 _too_many(f_name, args, kwonlyargs, varargs, num_defaults,
1558 num_pos, arg2value)
1559 if num_pos < num_args:
1560 req = args[:num_args - num_defaults]
1561 for arg in req:
1562 if arg not in arg2value:
1563 _missing_arguments(f_name, req, True, arg2value)
1564 for i, arg in enumerate(args[num_args - num_defaults:]):
1565 if arg not in arg2value:
1566 arg2value[arg] = defaults[i]
1567 missing = 0
1568 for kwarg in kwonlyargs:
1569 if kwarg not in arg2value:
1570 if kwonlydefaults and kwarg in kwonlydefaults:
1571 arg2value[kwarg] = kwonlydefaults[kwarg]
1572 else:
1573 missing += 1
1574 if missing:
1575 _missing_arguments(f_name, kwonlyargs, False, arg2value)

Callers

nothing calls this directly

Calls 9

getfullargspecFunction · 0.85
ismethodFunction · 0.85
minFunction · 0.85
tupleClass · 0.85
_too_manyFunction · 0.85
_missing_argumentsFunction · 0.85
enumerateFunction · 0.85
setFunction · 0.50
itemsMethod · 0.45

Tested by

no test coverage detected