commit: adf5b38050bd8544e6da27bf4b809dd1d6d90e01 Author: Brian Harring <ferringb <AT> gmail <DOT> com> AuthorDate: Sat Oct 25 00:34:02 2025 +0000 Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> CommitDate: Sat Oct 25 06:18:11 2025 +0000 URL: https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=adf5b380
hack: suppress deprecation notices pre python 3.13 Signed-off-by: Brian Harring <ferringb <AT> gmail.com> Part-of: https://github.com/pkgcore/snakeoil/pull/107 Closes: https://github.com/pkgcore/snakeoil/pull/107 Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org> src/snakeoil/_util.py | 16 ++++++++++++++++ src/snakeoil/klass/__init__.py | 7 ++++--- src/snakeoil/klass/immutable.py | 5 +++-- src/snakeoil/klass/properties.py | 5 +++-- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/snakeoil/_util.py b/src/snakeoil/_util.py new file mode 100644 index 0000000..cdac209 --- /dev/null +++ b/src/snakeoil/_util.py @@ -0,0 +1,16 @@ +__all__ = ("deprecated",) + +try: + from warnings import deprecated # pyright: ignore[reportAssignmentType] +except ImportError: + + def deprecated(_message): + """ + This is a noop; deprecation warnings are disabled for pre python + 3.13. + """ + + def f(thing): + return thing + + return f diff --git a/src/snakeoil/klass/__init__.py b/src/snakeoil/klass/__init__.py index 9191609..c26deb5 100644 --- a/src/snakeoil/klass/__init__.py +++ b/src/snakeoil/klass/__init__.py @@ -35,12 +35,13 @@ __all__ = ( import inspect import itertools -import warnings from collections import deque from functools import partial, wraps from importlib import import_module from operator import attrgetter +from snakeoil._util import deprecated + from ..caching import WeakInstMeta from .immutable import ( ImmutableInstance, @@ -271,7 +272,7 @@ def inject_richcmp_methods_from_cmp(scope): scope.setdefault(key, func) [email protected]( +@deprecated( "snakeoil.klass.chained_getter is deprecated. Use operator.attrgetter instead." ) class chained_getter(metaclass=partial(generic_equality, real_type=WeakInstMeta)): @@ -337,7 +338,7 @@ class chained_getter(metaclass=partial(generic_equality, real_type=WeakInstMeta) return self.getter(obj) -static_attrgetter = warnings.deprecated( +static_attrgetter = deprecated( "snakeoil.klass.static_attrgetter is deprecated. Use operator.attrgetter instead" )(chained_getter) instance_attrgetter = chained_getter diff --git a/src/snakeoil/klass/immutable.py b/src/snakeoil/klass/immutable.py index 46e6ee2..ee6efea 100644 --- a/src/snakeoil/klass/immutable.py +++ b/src/snakeoil/klass/immutable.py @@ -2,7 +2,8 @@ __all__ = ("immutable_instance", "inject_immutable_instance", "ImmutableInstance") import typing -import warnings + +from snakeoil._util import deprecated T = typing.TypeVar("T") @@ -39,7 +40,7 @@ def inject_immutable_instance(scope: dict[str, typing.Any]): scope.setdefault("__delattr__", _immutable_delattr) [email protected]( +@deprecated( "snakeoil.klass.ImmutableInstance will be removed in future versions. Use the metaclasses instead" ) class ImmutableInstance: diff --git a/src/snakeoil/klass/properties.py b/src/snakeoil/klass/properties.py index 18066e5..1da6042 100644 --- a/src/snakeoil/klass/properties.py +++ b/src/snakeoil/klass/properties.py @@ -11,7 +11,8 @@ __all__ = ( # even if no real code changed (since the id() continually moves)... import operator import typing -import warnings + +from snakeoil._util import deprecated from ..currying import post_curry @@ -303,7 +304,7 @@ def alias_method(attr, name=None, doc=None): return _asecond_level_call [email protected]("snakeoil.klass.alias will be removed in future versions") +@deprecated("snakeoil.klass.alias will be removed in future versions") class alias: """Decorator for making methods callable through aliases.
