Converts a list of positional arguments to a map of keyword arguments. Uses the function's signature for argument names. Note that this does not check whether the array contains enough arguments to satisfy the call. Args: args: Positional arguments to the function. extra_ke
(
self,
args: Sequence[Any],
extra_keyword_args: dict[str, Any] | None = None,
)
| 119 | return promoted_args |
| 120 | |
| 121 | def nameArgs( |
| 122 | self, |
| 123 | args: Sequence[Any], |
| 124 | extra_keyword_args: dict[str, Any] | None = None, |
| 125 | ) -> dict[str, Any]: |
| 126 | """Converts a list of positional arguments to a map of keyword arguments. |
| 127 | |
| 128 | Uses the function's signature for argument names. Note that this does not |
| 129 | check whether the array contains enough arguments to satisfy the call. |
| 130 | |
| 131 | Args: |
| 132 | args: Positional arguments to the function. |
| 133 | extra_keyword_args: Optional named arguments to add. |
| 134 | |
| 135 | Returns: |
| 136 | Keyword arguments to the function. |
| 137 | |
| 138 | Raises: |
| 139 | EEException: If conflicting arguments or too many of them are supplied. |
| 140 | """ |
| 141 | signature = self.getSignature() |
| 142 | arg_specs = signature['args'] |
| 143 | |
| 144 | # Handle positional arguments. |
| 145 | if len(arg_specs) < len(args): |
| 146 | raise ee_exception.EEException( |
| 147 | 'Too many (%d) arguments to function: %s' |
| 148 | % (len(args), signature.get('name')) |
| 149 | ) |
| 150 | named_args = { |
| 151 | arg_spec['name']: value for arg_spec, value in zip(arg_specs, args) |
| 152 | } |
| 153 | |
| 154 | # Handle keyword arguments. |
| 155 | if extra_keyword_args: |
| 156 | for name in extra_keyword_args: |
| 157 | if name in named_args: |
| 158 | raise ee_exception.EEException( |
| 159 | 'Argument %s specified as both positional and ' |
| 160 | 'keyword to function: %s' % (name, signature.get('name')) |
| 161 | ) |
| 162 | named_args[name] = extra_keyword_args[name] |
| 163 | # Unrecognized arguments are checked in promoteArgs(). |
| 164 | |
| 165 | return named_args |
| 166 | |
| 167 | def getReturnType(self) -> str: |
| 168 | return self.getSignature()['returns'] |