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

Method _bind

Lib/inspect.py:3095–3235  ·  view source on GitHub ↗

Private method. Don't use directly.

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

Source from the content-addressed store, hash-verified

3093 return self._hash_basis() == other._hash_basis()
3094
3095 def _bind(self, args, kwargs, *, partial=False):
3096 """Private method. Don't use directly."""
3097
3098 arguments = {}
3099
3100 parameters = iter(self.parameters.values())
3101 parameters_ex = ()
3102 arg_vals = iter(args)
3103
3104 pos_only_param_in_kwargs = []
3105
3106 while True:
3107 # Let's iterate through the positional arguments and corresponding
3108 # parameters
3109 try:
3110 arg_val = next(arg_vals)
3111 except StopIteration:
3112 # No more positional arguments
3113 try:
3114 param = next(parameters)
3115 except StopIteration:
3116 # No more parameters. That's it. Just need to check that
3117 # we have no `kwargs` after this while loop
3118 break
3119 else:
3120 if param.kind == _VAR_POSITIONAL:
3121 # That's OK, just empty *args. Let's start parsing
3122 # kwargs
3123 break
3124 elif param.name in kwargs:
3125 if param.kind == _POSITIONAL_ONLY:
3126 if param.default is _empty:
3127 msg = f'missing a required positional-only argument: {param.name!r}'
3128 raise TypeError(msg)
3129 # Raise a TypeError once we are sure there is no
3130 # **kwargs param later.
3131 pos_only_param_in_kwargs.append(param)
3132 continue
3133 parameters_ex = (param,)
3134 break
3135 elif (param.kind == _VAR_KEYWORD or
3136 param.default is not _empty):
3137 # That's fine too - we have a default value for this
3138 # parameter. So, lets start parsing `kwargs`, starting
3139 # with the current parameter
3140 parameters_ex = (param,)
3141 break
3142 else:
3143 # No default, not VAR_KEYWORD, not VAR_POSITIONAL,
3144 # not in `kwargs`
3145 if partial:
3146 parameters_ex = (param,)
3147 break
3148 else:
3149 if param.kind == _KEYWORD_ONLY:
3150 argtype = ' keyword-only'
3151 else:
3152 argtype = ''

Callers 2

bindMethod · 0.95
bind_partialMethod · 0.95

Calls 7

chainMethod · 0.80
valuesMethod · 0.45
appendMethod · 0.45
formatMethod · 0.45
extendMethod · 0.45
popMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected