Modify combinator _next signature

This commit is contained in:
Divyansh 2021-08-06 16:08:34 -07:00 коммит произвёл Chi Song
Родитель 50547b5433
Коммит 76bdd70e72
3 изменённых файлов: 14 добавлений и 24 удалений

Просмотреть файл

@ -39,20 +39,19 @@ class Combinator(subclasses.BaseClassWithRunbookMixin, InitializableMixin):
"""
result: Optional[Dict[str, VariableEntry]] = None
new_variables = self._next()
new_values = self._next()
if new_variables or self._is_first_time:
if new_values or self._is_first_time:
result = current_variables.copy()
if new_variables:
for name, new_variable in new_variables.items():
if new_values:
for name, new_value in new_values.items():
original_variable = result.get(name, None)
if original_variable:
copied_variable = original_variable.copy()
copied_variable.update(new_variable)
copied_variable.data = new_value
result[name] = copied_variable
else:
result[name] = new_variable
result[name] = VariableEntry(name, new_value)
self._is_first_time = False
return result
@ -63,7 +62,7 @@ class Combinator(subclasses.BaseClassWithRunbookMixin, InitializableMixin):
"""
...
def _next(self) -> Optional[Dict[str, VariableEntry]]:
def _next(self) -> Optional[Dict[str, Any]]:
"""
subclasses should implement this method to return a combination. Return
None means no more.

Просмотреть файл

@ -9,7 +9,6 @@ from dataclasses_json import dataclass_json
from lisa import schema
from lisa.combinator import Combinator
from lisa.util import constants
from lisa.variable import VariableEntry, load_from_variable_entry
@dataclass_json()
@ -46,13 +45,9 @@ class BatchCombinator(Combinator):
def type_schema(cls) -> Type[schema.TypedSchema]:
return BatchCombinatorSchema
def _next(self) -> Optional[Dict[str, VariableEntry]]:
result: Optional[Dict[str, VariableEntry]] = None
def _next(self) -> Optional[Dict[str, Any]]:
result: Optional[Dict[str, Any]] = None
if self._index < len(self._items):
result = {}
variables = self._items[self._index]
result = self._items[self._index]
self._index += 1
for name, value in variables.items():
loaded_dict = load_from_variable_entry(name, value)
result.update(loaded_dict)
return result

Просмотреть файл

@ -2,14 +2,13 @@
# Licensed under the MIT license.
from dataclasses import dataclass, field
from typing import Dict, List, Optional, Type
from typing import Any, Dict, List, Optional, Type
from dataclasses_json import dataclass_json
from lisa import schema
from lisa.combinator import Combinator
from lisa.util import constants
from lisa.variable import VariableEntry, load_from_variable_entry
@dataclass_json()
@ -60,8 +59,8 @@ class GridCombinator(Combinator):
def type_schema(cls) -> Type[schema.TypedSchema]:
return GridCombinatorSchema
def _next(self) -> Optional[Dict[str, VariableEntry]]:
result: Optional[Dict[str, VariableEntry]] = None
def _next(self) -> Optional[Dict[str, Any]]:
result: Optional[Dict[str, Any]] = None
is_overflow: bool = False
carry = 1
for item_index in range(len(self._indexes)):
@ -79,8 +78,5 @@ class GridCombinator(Combinator):
result = {}
for index, item in enumerate(self._items):
assert isinstance(item.value, list)
loaded_dict = load_from_variable_entry(
item.name, item.value[self._indexes[index]], item.is_secret
)
result.update(loaded_dict)
result[item.name] = item.value[self._indexes[index]]
return result