Spanish
Languages
English
Bengali
French
German
Japanese
Korean
Portuguese
Spanish
Tamil

qiskit.utils.wrap_method

wrap_method(cls, name, *, before=None, after=None)[fuente]

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.

Parámetros
  • 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.

Muestra

ValueError – if the named method is not defined on the class or any parent class.