Reassign state Var when fields on a Base instance change

Merged
MA
3y ago
+494-471

Refactor mutable type handling in State classes:

  • Create new MutableProxy object that wraps list, dict, set, and Base-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 MutableProxy associated with the original state and field_name.
  • When assigning a MutableProxy back 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