Source code for ocrd_utils.deprecate

import functools
import warnings

by user2357112 supports Monica

[docs]def deprecated_alias(**aliases): """ Deprecate a kwarg in favor of another kwarg """ def deco(f): @functools.wraps(f) def wrapper(*args, **kwargs): rename_kwargs(f.__name__, kwargs, aliases) return f(*args, **kwargs) return wrapper return deco
[docs]def rename_kwargs(func_name, kwargs, aliases): for alias, new in aliases.items(): if alias in kwargs: if new in kwargs: raise TypeError('{} received both {} and {}'.format( func_name, alias, new)) warnings.warn('{} is deprecated; use {}'.format(alias, new), DeprecationWarning) kwargs[new] = kwargs.pop(alias)