About cookies on this site Our websites require some cookies to function properly (required). In addition, other cookies may be used with your consent to analyze site usage, improve the user experience and for advertising. For more information, please review your options. By visiting our website, you agree to our processing of information as described in IBM’sprivacy statement. To provide a smooth navigation, your cookie preferences will be shared across the IBM web domains listed here.
qiskit.utils.wrap_method
wrap_method(cls, name, *, before=None, after=None)
Wrap the functionality the instance- or class method cls.name
with additional behaviour before
and after
.
This mutates cls
, replacing the attribute name
with the new functionality. This is useful when creating class decorators. The method is allowed to be defined on any parent class instead.
If either before
or after
are 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.
Parameters
- cls (
Type
) – the class to modify. - name (
str
) – the name of the method on the class to wrap. - before (
Optional
[Callable
]) – a callable that should be called before the method that is being wrapped. - after (
Optional
[Callable
]) – a callable that should be called after the method that is being wrapped.
Raises
ValueError – if the named method is not defined on the class or any parent class.
Was this page helpful?
Report a bug or request content on GitHub.