Developer Interface

This part of the documentation covers all the API of intercepts. All of intercepts’ functionality can be accessed by these 3 methods.

intercepts.register(obj, handler)

Registers an intercept handler.

Parameters:
  • obj (function or method) – The callable to intercept.
  • handler (Callable) – A function to handle the intercept.

Usage:

>>> import intercepts
>>> increment = lambda x: x + 1
>>> handler = lambda func, arg: arg - (func(arg) - arg)
>>> intercepts.register(increment, handler)
>>> increment(43)
42
intercepts.unregister(obj, depth=-1)

Unregisters the handlers for an object.

Parameters:
  • obj (function or method) – The callable for which to unregister handlers.
  • depth (int) – (optional) The maximum number of handlers to unregister. Defaults to all.
intercepts.unregister_all()

Unregisters all handlers.