- wrap_method(cls, name, *, before=None, after=None)[source]¶
Wrap the functionality the instance- or class method
cls.namewith additional behaviour
cls, replacing the attribute
namewith the new functionality. This is useful when creating class decorators. The method is allowed to be defined on any parent class instead.
afterare given, they should be callables with a compatible signature to the method referred to. They will be called immediately before or after the method as appropriate, and any return value will be ignored.
Type) -- the class to modify.
str) -- the name of the method on the class to wrap.
Callable]) -- a callable that should be called before the method that is being wrapped.
Callable]) -- a callable that should be called after the method that is being wrapped.
ValueError -- if the named method is not defined on the class or any parent class.