Skip to content

Commit

Permalink
chore: use FutureWarning rather than DeprecationWarning
Browse files Browse the repository at this point in the history
  • Loading branch information
XuehaiPan committed Jun 7, 2024
1 parent 1f5c69e commit c3b1da0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions optree/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`."""
Expand Down
14 changes: 13 additions & 1 deletion optree/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -581,15 +582,21 @@ 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)


@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
Expand All @@ -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, ...] = ()
Expand All @@ -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."""
Expand All @@ -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."""
Expand All @@ -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."""
Expand All @@ -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]],
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]

0 comments on commit c3b1da0

Please sign in to comment.