MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / format_argspec_plus

Function format_argspec_plus

lib/sqlalchemy/util/langhelpers.py:562–676  ·  view source on GitHub ↗

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
)

Source from the content-addressed store, hash-verified

560
561
562def format_argspec_plus(
563 fn: Union[Callable[..., Any], compat.FullArgSpec], grouped: bool = True
564) -> Dict[str, Optional[str]]:
565 """Returns a dictionary of formatted, introspected function arguments.
566
567 A enhanced variant of inspect.formatargspec to support code generation.
568
569 fn
570 An inspectable callable or tuple of inspect getargspec() results.
571 grouped
572 Defaults to True; include (parens, around, argument) lists
573
574 Returns:
575
576 args
577 Full inspect.formatargspec for fn
578 self_arg
579 The name of the first positional argument, varargs[0], or None
580 if the function defines no positional arguments.
581 apply_pos
582 args, re-written in calling rather than receiving syntax. Arguments are
583 passed positionally.
584 apply_kw
585 Like apply_pos, except keyword-ish args are passed as keywords.
586 apply_pos_proxied
587 Like apply_pos but omits the self/cls argument
588
589 Example::
590
591 >>> format_argspec_plus(lambda self, a, b, c=3, **d: 123)
592 {'grouped_args': '(self, a, b, c=3, **d)',
593 'self_arg': 'self',
594 'apply_kw': '(self, a, b, c=c, **d)',
595 'apply_pos': '(self, a, b, c, **d)'}
596
597 """
598 if callable(fn):
599 spec = compat.inspect_getfullargspec(fn)
600 else:
601 spec = fn
602
603 args = compat.inspect_formatargspec(*spec)
604
605 apply_pos = compat.inspect_formatargspec(
606 spec[0], spec[1], spec[2], None, spec[4]
607 )
608
609 if spec[0]:
610 self_arg = spec[0][0]
611
612 apply_pos_proxied = compat.inspect_formatargspec(
613 spec[0][1:], spec[1], spec[2], None, spec[4]
614 )
615
616 elif spec[1]:
617 # I'm not sure what this is
618 self_arg = "%s[0]" % spec[1]
619

Callers 4

instrumentFunction · 0.90
decorateFunction · 0.90
decorateFunction · 0.85
format_argspec_initFunction · 0.85

Calls 1

castFunction · 0.70

Tested by 1

decorateFunction · 0.72