Decorator and utilities for deprecating functions, parameters, and classes with zero boilerplate
pip install philiprehberger-deprecateDecorator and utilities for deprecating functions, parameters, and classes with zero boilerplate.
pip install philiprehberger-deprecate
from philiprehberger_deprecate import (
deprecated,
deprecated_class,
deprecated_module,
deprecated_param,
)
@deprecated(remove_in="2.0.0", alternative="new_fetch")
def old_fetch(url: str) -> str:
...
Calling old_fetch() emits:
DeprecationWarning: Function 'old_fetch' is deprecated. Will be removed in 2.0.0. Use 'new_fetch' instead.
@deprecated_param("color", renamed_to="colour", remove_in="2.0.0")
def draw(shape: str, *, colour: str = "red") -> None:
...
draw(shape="circle", color="blue") # warns and forwards color -> colour
@deprecated_class(remove_in="3.0.0", alternative="NewClient")
class OldClient:
def __init__(self, host: str) -> None:
self.host = host
Instantiating OldClient() emits a DeprecationWarning.
# in mypkg/legacy/__init__.py
from philiprehberger_deprecate import deprecated_module
deprecated_module(__name__, remove_in="2.0.0", alternative="mypkg.modern")
Importing mypkg.legacy emits:
DeprecationWarning: Module 'mypkg.legacy' is deprecated. Will be removed in 2.0.0. Use 'mypkg.modern' instead.
| Function | Description |
|---|---|
deprecated(remove_in, *, alternative, message) | Function decorator that emits DeprecationWarning on each call |
deprecated_param(param, *, renamed_to, remove_in) | Function decorator that warns when a deprecated parameter is passed and optionally maps it to its replacement |
deprecated_class(remove_in, *, alternative, message) | Class decorator that emits DeprecationWarning on instantiation |
deprecated_module(name, *, remove_in, alternative, message) | Emits DeprecationWarning once when a deprecated module is imported |
pip install -e .
python -m pytest tests/ -v
If you find this project useful: