Source code for semi_cr.core.helpers
import functools
import rich
[docs]
def deprecated(message):
"""Mark a function as deprecated, warning on each call.
Use as a decorator factory: pass the message you want shown, and the
decorated function will emit that message as a ``DeprecationWarning``
every time it is called, before running as normal.
Example::
@deprecated("Use new_function() instead; removed in v3.0.")
def old_function():
...
Args:
message: The warning text shown when the decorated function is
called. Include what to use instead and, if known, when the
function will be removed.
Returns:
A decorator that wraps the target function. The wrapper preserves
the original function's name, docstring, and signature (via
``functools.wraps``), and reports the warning against the caller's
line (``stacklevel=2``) so it's easy to locate the offending usage.
Note:
``DeprecationWarning`` is hidden by default except in ``__main__``
and under test runners such as pytest. This is intentional: the
warning targets developers, not end users. If you need it visible
everywhere, change the category to ``FutureWarning``.
"""
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
rich.print(f"[yellow]Deprecation warning: {message}[/yellow]")
return func(*args, **kwargs)
return wrapper
return decorator