MCPcopy Create free account
hub / github.com/RustPython/RustPython / Signature

Class Signature

Lib/inspect.py:2942–3316  ·  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

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

Callers 2

__signature__Method · 0.90

Calls

no outgoing calls

Tested by 1