commit: 6bdf629861d6266d2b99d59479f43ac0471cd59a
Author: Brian Harring <ferringb <AT> gmail <DOT> com>
AuthorDate: Sun Nov 30 21:21:38 2025 +0000
Commit: Brian Harring <ferringb <AT> gmail <DOT> com>
CommitDate: Sun Nov 30 21:25:18 2025 +0000
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=6bdf6298
refactor(depreciation):: add suppress_deprecations
Signed-off-by: Brian Harring <ferringb <AT> gmail.com>
src/snakeoil/deprecation.py | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/src/snakeoil/deprecation.py b/src/snakeoil/deprecation.py
index 8cd3730..6aca45e 100644
--- a/src/snakeoil/deprecation.py
+++ b/src/snakeoil/deprecation.py
@@ -1,8 +1,13 @@
__all__ = ("deprecated",)
+import functools
+import typing
import warnings
from contextlib import contextmanager
+T = typing.TypeVar("T")
+P = typing.ParamSpec("P")
+
_import_failed = False
deprecation_frame_depth = 1 # some old code does "reach up the stack" tricks.
Thus it has to know how far up to climb.
try:
@@ -41,3 +46,14 @@ def suppress_deprecation_warning():
with warnings.catch_warnings():
warnings.simplefilter(action="ignore", category=DeprecationWarning)
yield
+
+
+def suppress_deprecations(thing: typing.Callable[P, T]) -> typing.Callable[P,
T]:
+ """Decorator to suppress all deprecation warnings within the callable"""
+
+ @functools.wraps(thing)
+ def f(*args, **kwargs) -> T:
+ with suppress_deprecation_warning():
+ return thing(*args, **kwargs)
+
+ return f