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.aqua.utils.name_args

name_args(mapping, skip=0)

GitHub

Decorator to convert unnamed arguments to named ones.

Can be used to deprecate old signatures of a function, e.g.

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

@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!
Was this page helpful?
Report a bug or request content on GitHub.