qiskit-documentation/docs/api/qiskit/0.31/qiskit.utils.name_args.mdx

39 lines
1.1 KiB
Plaintext

---
title: name_args (v0.31)
description: API reference for qiskit.utils.name_args in qiskit v0.31
in_page_toc_min_heading_level: 1
python_api_type: function
python_api_name: qiskit.utils.name_args
---
<span id="qiskit-utils-name-args" />
# qiskit.utils.name\_args
<Function id="qiskit.utils.name_args" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.18/qiskit/utils/name_unnamed_args.py" signature="name_args(mapping, skip=0)">
Decorator to convert unnamed arguments to named ones.
Can be used to deprecate old signatures of a function, e.g.
```python
old_f(a: TypeA, b: TypeB, c: TypeC)
new_f(a: TypeA, d: TypeD, b: TypeB=None, c: TypeC=None)
```
Then, to support the old signature this decorator can be used as
```python
@name_args([
('a'), # stays the same
('d', {TypeB: 'b'}), # if arg is of type TypeB, call if 'b' else 'd'
('b', {TypeC: 'c'})
])
def new_f(a: TypeA, d: TypeD, b: TypeB=None, c: TypeC=None):
if b is not None:
# raise warning, this is deprecated!
if c is not None:
# raise warning, this is deprecated!
```
</Function>