feat: add deprecated decorator

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2024-05-02 21:51:35 +02:00
parent 4a5d1a971a
commit 067a102b6b
2 changed files with 24 additions and 0 deletions

22
kiauh/utils/decorators.py Normal file
View File

@@ -0,0 +1,22 @@
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/dw-0/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
# ======================================================================= #
import warnings
from typing import Callable
def deprecated(info: str = "", replaced_by: Callable = None) -> Callable:
def decorator(func):
def wrapper(*args, **kwargs):
msg = f"{info}{replaced_by.__name__ if replaced_by else ''}"
warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
return func(*args, **kwargs)
return wrapper
return decorator