MCPcopy Index your code
hub / github.com/python/cpython / Signature

Class Signature

Lib/inspect.py:2949–3323  ·  view source on GitHub ↗

A Signature object represents the overall signature of a function. It stores a Parameter object for each parameter accepted by the function, as well as information specific to the function itself. A Signature object has the following public attributes and methods: * parameters : Or

Source from the content-addressed store, hash-verified

2947
2948
2949class Signature:
2950 """A Signature object represents the overall signature of a function.
2951 It stores a Parameter object for each parameter accepted by the
2952 function, as well as information specific to the function itself.
2953
2954 A Signature object has the following public attributes and methods:
2955
2956 * parameters : OrderedDict
2957 An ordered mapping of parameters' names to the corresponding
2958 Parameter objects (keyword-only arguments are in the same order
2959 as listed in `code.co_varnames`).
2960 * return_annotation : object
2961 The annotation for the return type of the function if specified.
2962 If the function has no annotation for its return type, this
2963 attribute is set to `Signature.empty`.
2964 * bind(*args, **kwargs) -> BoundArguments
2965 Creates a mapping from positional and keyword arguments to
2966 parameters.
2967 * bind_partial(*args, **kwargs) -> BoundArguments
2968 Creates a partial mapping from positional and keyword arguments
2969 to parameters (simulating 'functools.partial' behavior.)
2970 """
2971
2972 __slots__ = ('_return_annotation', '_parameters')
2973
2974 _parameter_cls = Parameter
2975 _bound_arguments_cls = BoundArguments
2976
2977 empty = _empty
2978
2979 def __init__(self, parameters=None, *, return_annotation=_empty,
2980 __validate_parameters__=True):
2981 """Constructs Signature from the given list of Parameter
2982 objects and 'return_annotation'. All arguments are optional.
2983 """
2984
2985 if parameters is None:
2986 params = OrderedDict()
2987 else:
2988 if __validate_parameters__:
2989 params = OrderedDict()
2990 top_kind = _POSITIONAL_ONLY
2991 seen_default = False
2992 seen_var_parameters = set()
2993
2994 for param in parameters:
2995 kind = param.kind
2996 name = param.name
2997
2998 if kind in (_VAR_POSITIONAL, _VAR_KEYWORD):
2999 if kind in seen_var_parameters:
3000 msg = f'more than one {kind.description} parameter'
3001 raise ValueError(msg)
3002
3003 seen_var_parameters.add(kind)
3004
3005 if kind < top_kind:
3006 msg = (

Callers 2

__signature__Method · 0.90

Calls

no outgoing calls

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…