dtoolkit.util._decorator.deprecated_alias#

dtoolkit.util._decorator.deprecated_alias(warning_msg: str = "'{func_name}'s parameter '{old_alias}' is deprecated, please use the parameter '{new_alias}'.", error_msg: str = "'{func_name}' shouldn't received both '{old_alias}' and '{new_alias}' parameters at the same time.", **aliases)[source]#

Used as a decorator when deprecating old function argument names, while keeping backwards compatibility.

Parameters:
warning_msgstr

The message of DeprecationWarning. It should be a string or a string template. If a string template defaults input func_name, old_alias and new_alias.

error_msgstr

The message of TypeError. It should be a string or a string template. If a string template defaults input func_name, old_alias and new_alias.

**aliasesdict

Dictionary of aliases for a function’s arguments, like {old_alias: new_alias}.

Raises:
DeprecationWarning

If old_alias is input into the function.

TypeError

If old_alias and new_alias are both input into the function.

Examples

>>> from dtoolkit.util._decorator import deprecated_alias
>>> @deprecated_alias(a='alpha', b='beta')
... def plus(alpha, beta):
...     return alpha + beta
>>> plus(a=1, beta=2)
3