qiskit-documentation/docs/api/qiskit/0.41/qiskit.utils.wrap_method.mdx

30 lines
1.4 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: wrap_method
description: API reference for qiskit.utils.wrap_method
in_page_toc_min_heading_level: 1
python_api_type: function
python_api_name: qiskit.utils.wrap_method
---
# qiskit.utils.wrap\_method
<Function id="qiskit.utils.wrap_method" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.23/qiskit/utils/classtools.py" signature="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.
</Function>