Promotes arguments to their types based on the function's signature. Verifies that all required arguments are provided and no unknown arguments are present. Args: args: A dictionary of keyword arguments to the function. Returns: A dictionary of promoted arguments.
(self, args: dict[str, Any])
| 77 | return Function._promoter(result, self.getReturnType()) |
| 78 | |
| 79 | def promoteArgs(self, args: dict[str, Any]) -> dict[str, Any]: |
| 80 | """Promotes arguments to their types based on the function's signature. |
| 81 | |
| 82 | Verifies that all required arguments are provided and no unknown arguments |
| 83 | are present. |
| 84 | |
| 85 | Args: |
| 86 | args: A dictionary of keyword arguments to the function. |
| 87 | |
| 88 | Returns: |
| 89 | A dictionary of promoted arguments. |
| 90 | |
| 91 | Raises: |
| 92 | EEException: If unrecognized arguments are passed or required ones are |
| 93 | missing. |
| 94 | """ |
| 95 | signature = self.getSignature() |
| 96 | arg_specs = signature['args'] |
| 97 | |
| 98 | # Promote all recognized args. |
| 99 | promoted_args: dict[str, Any] = {} |
| 100 | known: set[str] = set() |
| 101 | for arg_spec in arg_specs: |
| 102 | name = arg_spec['name'] |
| 103 | if name in args: |
| 104 | promoted_args[name] = Function._promoter(args[name], arg_spec['type']) |
| 105 | elif not arg_spec.get('optional'): |
| 106 | raise ee_exception.EEException( |
| 107 | 'Required argument (%s) missing to function: %s' |
| 108 | % (name, signature.get('name'))) |
| 109 | known.add(name) |
| 110 | |
| 111 | # Check for unknown arguments. |
| 112 | unknown = set(args.keys()).difference(known) |
| 113 | if unknown: |
| 114 | raise ee_exception.EEException( |
| 115 | 'Unrecognized arguments %s to function: %s' |
| 116 | % (unknown, signature.get('name')) |
| 117 | ) |
| 118 | |
| 119 | return promoted_args |
| 120 | |
| 121 | def nameArgs( |
| 122 | self, |