more minor pickle improvements

This commit is contained in:
Benedikt Bartscher 2024-12-08 00:39:06 +01:00
parent e2583c48c9
commit d5265ae553
No known key found for this signature in database
2 changed files with 5 additions and 4 deletions

View File

@ -2107,6 +2107,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
# Never serialize parent_state or substates.
state["__dict__"].pop("parent_state", None)
state["__dict__"].pop("substates", None)
state["__dict__"].pop("dirty_vars", None)
state["__dict__"].pop("dirty_substates", None)
state["__dict__"].pop("_was_touched", None)
# Remove all inherited vars.
for inherited_var_name in self.inherited_vars:
@ -2123,6 +2125,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
"""
state["__dict__"]["parent_state"] = None
state["__dict__"]["substates"] = {}
state["__dict__"]["dirty_vars"] = set()
state["__dict__"]["dirty_substates"] = set()
super().__setstate__(state)
def _check_state_size(

View File

@ -2513,10 +2513,7 @@ def test_mutable_copy(mutable_state: MutableTestState, copy_func: Callable):
assert getattr(ms_copy, attr) is not getattr(mutable_state, attr)
ms_copy.custom.array.append(42)
assert "custom" in ms_copy.dirty_vars
if copy_func is copy.copy:
assert "custom" in mutable_state.dirty_vars
else:
assert not mutable_state.dirty_vars
assert not mutable_state.dirty_vars
@pytest.mark.parametrize(