pg.patcher

Accessible via pg.patcher, pg.patching.patcher.

patcher(args=None, name=None)[source]

Decorate a function into a Patcher and register it.

A patcher function is defined as: :rtype: Any

<patcher_fun> := <fun_name>(<target>, [parameters])

The signature takes at least one argument as the patching target, with additional arguments as patching parameters to control the details of this patch.

Example:

@pg.patching.patcher([
  ('x': pg.typing.Int())
])
def increment(v, x=1):
  return pg.symbolic.get_rebind_dict(
      lambda k, v, p: v + x if isinstance(v, int) else v)

# This patcher can be called via:
# pg.patching.apply(v, [increment(x=2)])
# or pg.patching.apply(v, ['increment?x=2'])
Parameters:
  • args – A list of (arg_name, arg_value_spec) to schematize patcher arguments.

  • name – String to be used as patcher name in URI. If None, function name will be used as patcher name.

Returns:

A decorator that converts a function into a Patcher subclass.