pg.patch_on_key¶
Accessible via pg.patch_on_key
, pg.patching.patch_on_key
.
- patch_on_key(src, regex, value=None, value_fn=None, skip_notification=None)[source]¶
Recursively patch values on matched keys (leaf-node names).
Example:
d = pg.Dict(a=0, b=2) print(pg.patching.patch_on_key(d, 'a', value=3)) # {a=3, b=2} print(pg.patching.patch_on_key(d, '.', value=3)) # {a=3, b=3} @pg.members([ ('x', schema.Int()) ]) class A(pg.Object): def _on_init(self): super()._on_init() self._num_changes = 0 def _on_change(self, updates): super()._on_change(updates) self._num_changes += 1 a = A() pg.patching.patch_on_key(a, 'x', value=2) # a._num_changes is 1. pg.patching.patch_on_key(a, 'x', value=3) # a._num_changes is 2. pg.patching.patch_on_keys(a, 'x', value=4, skip_notification=True) # a._num_changes is still 2.
- Return type:
- Parameters:
src – symbolic value to patch.
regex – Regex for key name.
value – New value for field that satisfy condition.
value_fn – Callable object that produces new value based on old value. If not None, value must be None.
skip_notification – If True, on_change event will not be triggered for this operation. If None, the behavior is decided by pg.notify_on_rebind. Please see symbolic.Symbolic.rebind for details.
- Returns:
src after being patched.