|
3 | 3 | from decimal import Decimal |
4 | 4 | from functools import reduce |
5 | 5 | from operator import getitem |
6 | | -from typing import Any |
| 6 | +from typing import Any, Iterable |
7 | 7 |
|
8 | 8 | import requests |
9 | 9 | from binascii import Error |
@@ -178,23 +178,23 @@ def validate_oracle_fallback_fsp( |
178 | 178 | ) |
179 | 179 |
|
180 | 180 |
|
181 | | -def validate_outcome_space_conditions( |
182 | | - base_case_condition: str, |
183 | | - edge_case_conditions: list[str], |
184 | | - outcome_point_dict: dict[Any, Any], |
| 181 | +def validate_outcome_space_template_variables( |
| 182 | + values: Iterable[str], outcome_point_dict: dict[Any, Any] |
185 | 183 | ) -> None: |
186 | | - conditions = [base_case_condition] + edge_case_conditions |
187 | | - schemas = ["BaseCaseResolution"] + [ |
188 | | - f"EdgeCase[{i}]" for i in range(len(edge_case_conditions)) |
189 | | - ] |
190 | | - for condition, schema in zip(conditions, schemas): |
191 | | - for variable in re.findall(r"{(.+?)}", condition): |
192 | | - parts = variable.split(".") |
| 184 | + for value in values: |
| 185 | + for variable in re.findall(r"{(.*?)}", value): |
193 | 186 | try: |
194 | | - reduce(getitem, parts, outcome_point_dict) |
195 | | - except KeyError: |
| 187 | + referred_value = reduce( |
| 188 | + getitem, variable.split("."), outcome_point_dict |
| 189 | + ) |
| 190 | + except (TypeError, KeyError): |
| 191 | + raise ValueError( |
| 192 | + f"OutcomeSpace: Invalid template variable '{variable}'" |
| 193 | + ) |
| 194 | + if isinstance(referred_value, dict) or isinstance(referred_value, list): # type: ignore |
196 | 195 | raise ValueError( |
197 | | - f"{schema}: condition: Invalid template variable '{variable}'" |
| 196 | + f"OutcomeSpace: Template variable '{variable}' " |
| 197 | + "should not refer to a nested object or list" |
198 | 198 | ) |
199 | 199 |
|
200 | 200 |
|
|
0 commit comments