Returns a dictionary of formatted, introspected function arguments. A enhanced variant of inspect.formatargspec to support code generation. fn An inspectable callable or tuple of inspect getargspec() results. grouped Defaults to True; include (parens, around, argument) lis
(
fn: Union[Callable[..., Any], compat.FullArgSpec], grouped: bool = True
)
| 519 | |
| 520 | |
| 521 | def format_argspec_plus( |
| 522 | fn: Union[Callable[..., Any], compat.FullArgSpec], grouped: bool = True |
| 523 | ) -> Dict[str, Optional[str]]: |
| 524 | """Returns a dictionary of formatted, introspected function arguments. |
| 525 | |
| 526 | A enhanced variant of inspect.formatargspec to support code generation. |
| 527 | |
| 528 | fn |
| 529 | An inspectable callable or tuple of inspect getargspec() results. |
| 530 | grouped |
| 531 | Defaults to True; include (parens, around, argument) lists |
| 532 | |
| 533 | Returns: |
| 534 | |
| 535 | args |
| 536 | Full inspect.formatargspec for fn |
| 537 | self_arg |
| 538 | The name of the first positional argument, varargs[0], or None |
| 539 | if the function defines no positional arguments. |
| 540 | apply_pos |
| 541 | args, re-written in calling rather than receiving syntax. Arguments are |
| 542 | passed positionally. |
| 543 | apply_kw |
| 544 | Like apply_pos, except keyword-ish args are passed as keywords. |
| 545 | apply_pos_proxied |
| 546 | Like apply_pos but omits the self/cls argument |
| 547 | |
| 548 | Example:: |
| 549 | |
| 550 | >>> format_argspec_plus(lambda self, a, b, c=3, **d: 123) |
| 551 | {'grouped_args': '(self, a, b, c=3, **d)', |
| 552 | 'self_arg': 'self', |
| 553 | 'apply_kw': '(self, a, b, c=c, **d)', |
| 554 | 'apply_pos': '(self, a, b, c, **d)'} |
| 555 | |
| 556 | """ |
| 557 | if callable(fn): |
| 558 | spec = compat.inspect_getfullargspec(fn) |
| 559 | else: |
| 560 | spec = fn |
| 561 | |
| 562 | args = compat.inspect_formatargspec(*spec) |
| 563 | |
| 564 | apply_pos = compat.inspect_formatargspec( |
| 565 | spec[0], spec[1], spec[2], None, spec[4] |
| 566 | ) |
| 567 | |
| 568 | if spec[0]: |
| 569 | self_arg = spec[0][0] |
| 570 | |
| 571 | apply_pos_proxied = compat.inspect_formatargspec( |
| 572 | spec[0][1:], spec[1], spec[2], None, spec[4] |
| 573 | ) |
| 574 | |
| 575 | elif spec[1]: |
| 576 | # I'm not sure what this is |
| 577 | self_arg = "%s[0]" % spec[1] |
| 578 |