Skip to content

Commit

Permalink
implement set by kwargs in dict_state
Browse files Browse the repository at this point in the history
  • Loading branch information
pLeminoq committed Dec 13, 2024
1 parent 893600f commit dec7801
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions widget_state/dict_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,23 @@ def values(self) -> list[Any]:
"""
return [attr.value for attr in self]

def set(self, *args: BasicState[Any] | Primitive) -> None:
def set(
self,
*args: BasicState[Any] | Primitive,
**kwargs: dict[str, BasicState[Any] | Primitive],
) -> None:
"""
Reassign all internal basic state values and only
Reassign internal basic state values and only
trigger a notification afterwards.
"""
assert len(args) == len(self)

with self:
for i, arg in enumerate(args):
self[i].value = arg.value if isinstance(arg, BasicState) else arg

_dict = self.dict()
for name, kwarg in kwargs.items():
attr = _dict[name]
assert isinstance(attr, BasicState)
attr.value = kwarg.value if isinstance(kwarg, BasicState) else kwarg

0 comments on commit dec7801

Please sign in to comment.