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