Skip to main contentIBM Quantum Documentation
This page is from an old version of Qiskit SDK and does not exist in the latest version. We recommend you migrate to the latest version. See the release notes for more information.

qiskit.utils.wrap_method

wrap_method(cls, name, *, before=None, after=None)

GitHub

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.