Reassign state Var when fields on a Base instance change
Merged
MA
3y ago+494+494+012345678901234567890123456789-471-471-012345678901234567890123456789
Refactor mutable type handling in State classes:
- Create new
MutableProxyobject that wrapslist,dict,set, andBase-derived objects coming from the State. - When certain
__magic_attrs__are accessed on wrapped objects, and they are callable, mark the associated var field in the state as dirty. - When accessing attributes or items through the proxy, and the resulting object is also mutable, then also wrap it in
MutableProxyassociated with the original state and field_name. - When assigning a
MutableProxyback to the state, actually assign the wrapped object.
This approach does not incur as much runtime overhead as the current implementation, since it does not create copies of objects just for state tracking and does not create copies of objects when assigning back to the state. Instead it just wraps the original mutable object.
Fixes #1675