Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion burr/core/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,10 @@ def wipe(self, delete: Optional[list[str]] = None, keep: Optional[list[str]] = N
)
if delete is not None:
fields_to_delete = delete
else:
elif keep is not None:
fields_to_delete = [key for key in self._state if key not in keep]
else:
fields_to_delete = list(self._state)
return self.apply_operation(DeleteField(fields_to_delete))

def merge(self, other: "State") -> "State[StateType]":
Expand Down
7 changes: 7 additions & 0 deletions tests/core/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ def test_state_wipe_keep():
assert wiped.get_all() == {"foo": "bar"}


def test_state_wipe_all():
# wipe() with neither delete nor keep should clear everything, as documented.
state = State({"foo": "bar", "baz": "qux"})
wiped = state.wipe()
assert wiped.get_all() == {}


def test_state_append_validate_failure():
state = State({"foo": "bar"})
with pytest.raises(ValueError, match="non-appendable"):
Expand Down
Loading