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

Method _bind

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

Private method. Don't use directly.

(self, args, kwargs, *, partial=False)

Source from the content-addressed store, hash-verified

3057 return self._hash_basis() == other._hash_basis()
3058
3059 def _bind(self, args, kwargs, *, partial=False):
3060 """Private method. Don't use directly."""
3061
3062 arguments = {}
3063
3064 parameters = iter(self.parameters.values())
3065 parameters_ex = ()
3066 arg_vals = iter(args)
3067
3068 while True:
3069 # Let's iterate through the positional arguments and corresponding
3070 # parameters
3071 try:
3072 arg_val = next(arg_vals)
3073 except StopIteration:
3074 # No more positional arguments
3075 try:
3076 param = next(parameters)
3077 except StopIteration:
3078 # No more parameters. That's it. Just need to check that
3079 # we have no `kwargs` after this while loop
3080 break
3081 else:
3082 if param.kind == _VAR_POSITIONAL:
3083 # That's OK, just empty *args. Let's start parsing
3084 # kwargs
3085 break
3086 elif param.name in kwargs:
3087 if param.kind == _POSITIONAL_ONLY:
3088 msg = '{arg!r} parameter is positional only, ' \
3089 'but was passed as a keyword'
3090 msg = msg.format(arg=param.name)
3091 raise TypeError(msg) from None
3092 parameters_ex = (param,)
3093 break
3094 elif (param.kind == _VAR_KEYWORD or
3095 param.default is not _empty):
3096 # That's fine too - we have a default value for this
3097 # parameter. So, lets start parsing `kwargs`, starting
3098 # with the current parameter
3099 parameters_ex = (param,)
3100 break
3101 else:
3102 # No default, not VAR_KEYWORD, not VAR_POSITIONAL,
3103 # not in `kwargs`
3104 if partial:
3105 parameters_ex = (param,)
3106 break
3107 else:
3108 msg = 'missing a required argument: {arg!r}'
3109 msg = msg.format(arg=param.name)
3110 raise TypeError(msg) from None
3111 else:
3112 # We have a positional argument to process
3113 try:
3114 param = next(parameters)
3115 except StopIteration:
3116 raise TypeError('too many positional arguments') from None

Callers 2

bindMethod · 0.95
bind_partialMethod · 0.95

Calls 6

tupleClass · 0.85
chainMethod · 0.80
valuesMethod · 0.45
formatMethod · 0.45
extendMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected