Skip to content

Commit

Permalink
[melobot] Fix deprecated warning feature
Browse files Browse the repository at this point in the history
  • Loading branch information
aicorein committed Dec 10, 2024
1 parent 0dae81d commit d1d67f0
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/melobot/typ.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,16 +438,24 @@ def foo(val: Any | VoidType = VoidType.VOID) -> None:
VOID = type("_VOID", (), {})


def deprecate_warn(msg: str) -> None:
from .ctx import LoggerCtx

if logger := LoggerCtx().try_get():
logger.warning(msg)
warnings.simplefilter("always", DeprecationWarning)
warnings.warn(msg, category=DeprecationWarning, stacklevel=1)
warnings.simplefilter("default", DeprecationWarning)


def deprecated(msg: str) -> Callable[[Callable[P, T]], Callable[P, T]]:

def decorator(func: Callable[P, T]) -> Callable[P, T]:

@wraps(func)
def deprecate_wrapped(*args: P.args, **kwargs: P.kwargs) -> T:
warnings.warn(
f"使用了弃用函数/方法 {func.__qualname__}: {msg}",
category=DeprecationWarning,
stacklevel=2,
deprecate_warn(
f"使用了弃用函数/方法 {func.__module__}.{func.__qualname__}: {msg}"
)
return func(*args, **kwargs)

Expand Down

0 comments on commit d1d67f0

Please sign in to comment.