From c3b1da09af2380665802152a0ab75f7ee9cb838e Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Fri, 7 Jun 2024 17:21:24 +0000 Subject: [PATCH] chore: use `FutureWarning` rather than `DeprecationWarning` --- optree/functools.py | 1 + optree/registry.py | 14 +++++++++++++- pyproject.toml | 4 ++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/optree/functools.py b/optree/functools.py index a856ce35..dab0a96d 100644 --- a/optree/functools.py +++ b/optree/functools.py @@ -167,6 +167,7 @@ def tree_unflatten( # type: ignore[override] @deprecated( 'The class `optree.Partial` is deprecated and will be removed in a future version. ' 'Please use `optree.functools.partial` instead.', + category=FutureWarning, ) class Partial(partial): """Deprecated alias for :class:`partial`.""" diff --git a/optree/registry.py b/optree/registry.py index 5653fcc8..4360e169 100644 --- a/optree/registry.py +++ b/optree/registry.py @@ -20,6 +20,7 @@ import functools import inspect import sys +import warnings from collections import OrderedDict, defaultdict, deque, namedtuple from operator import itemgetter, methodcaller from threading import Lock @@ -581,8 +582,13 @@ def _pytree_node_registry_get( #################################################################################################### +warnings.filterwarnings('ignore', category=FutureWarning, module=__name__, append=True) -@deprecated('The function `_sorted_keys` is deprecated and will be removed in a future version.') + +@deprecated( + 'The function `_sorted_keys` is deprecated and will be removed in a future version.', + category=FutureWarning, +) def _sorted_keys(dct: dict[KT, VT]) -> list[KT]: return total_order_sorted(dct) @@ -590,6 +596,7 @@ def _sorted_keys(dct: dict[KT, VT]) -> list[KT]: @deprecated( 'The key path API is deprecated and will be removed in a future version. ' 'Please use the accessor API instead.', + category=FutureWarning, ) class KeyPathEntry(NamedTuple): key: Any @@ -612,6 +619,7 @@ def pprint(self) -> str: @deprecated( 'The key path API is deprecated and will be removed in a future version. ' 'Please use the accessor API instead.', + category=FutureWarning, ) class KeyPath(NamedTuple): keys: tuple[KeyPathEntry, ...] = () @@ -636,6 +644,7 @@ def pprint(self) -> str: @deprecated( 'The key path API is deprecated and will be removed in a future version. ' 'Please use the accessor API instead.', + category=FutureWarning, ) class GetitemKeyPathEntry(KeyPathEntry): """The key path entry class for sequences and dictionaries.""" @@ -648,6 +657,7 @@ def pprint(self) -> str: @deprecated( 'The key path API is deprecated and will be removed in a future version. ' 'Please use the accessor API instead.', + category=FutureWarning, ) class AttributeKeyPathEntry(KeyPathEntry): """The key path entry class for namedtuples.""" @@ -660,6 +670,7 @@ def pprint(self) -> str: @deprecated( 'The key path API is deprecated and will be removed in a future version. ' 'Please use the accessor API instead.', + category=FutureWarning, ) class FlattenedKeyPathEntry(KeyPathEntry): # fallback """The fallback key path entry class.""" @@ -676,6 +687,7 @@ def pprint(self) -> str: @deprecated( 'The key path API is deprecated and will be removed in a future version. ' 'Please use the accessor API instead.', + category=FutureWarning, ) def register_keypaths( cls: type[CustomTreeNode[T]], diff --git a/pyproject.toml b/pyproject.toml index cdbac30a..60db63ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -262,6 +262,6 @@ ban-relative-imports = "all" [tool.pytest.ini_options] filterwarnings = [ "error", - "ignore:The class `optree.Partial` is deprecated and will be removed in a future version. Please use `optree.functools.partial` instead.:DeprecationWarning", - "ignore:The key path API is deprecated and will be removed in a future version. Please use the accessor API instead.:DeprecationWarning", + "ignore:The class `optree.Partial` is deprecated and will be removed in a future version. Please use `optree.functools.partial` instead.:FutureWarning", + "ignore:The key path API is deprecated and will be removed in a future version. Please use the accessor API instead.:FutureWarning", ]