From 2528148c2e9bdee9e2408476d6dc04f5b2d726ba Mon Sep 17 00:00:00 2001 From: Nathaniel Starkman Date: Wed, 3 Jul 2024 16:35:03 -0400 Subject: [PATCH] use deprecation decorator (#177) Signed-off-by: nstarman --- plum/__init__.py | 2 ++ plum/parametric.py | 11 +++-------- plum/util.py | 10 +++------- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/plum/__init__.py b/plum/__init__.py index 543a620..5ba39dd 100644 --- a/plum/__init__.py +++ b/plum/__init__.py @@ -24,6 +24,8 @@ from .util import * # noqa: F401, F403 # Deprecated +# isort: split +from .parametric import Val # noqa: F401, F403 from .util import multihash # noqa: F401, F403 # Ensure that type checking is always entirely correct! The default O(1) strategy diff --git a/plum/parametric.py b/plum/parametric.py index 08b0cef..2bfaf77 100644 --- a/plum/parametric.py +++ b/plum/parametric.py @@ -1,7 +1,8 @@ import contextlib -import warnings from typing import Type, TypeVar, Union +from typing_extensions import deprecated + import beartype.door from beartype.roar import BeartypeDoorNonpepException @@ -19,7 +20,6 @@ "type_unparametrized", "kind", "Kind", - "Val", ] T = TypeVar("T") @@ -632,6 +632,7 @@ def get(self): Kind = kind() #: A default kind provided for convenience. +@deprecated("Use `typing.Literal[val]` instead.") @parametric class Val: """A parametric type used to move information from the value domain to the type @@ -661,12 +662,6 @@ def __init__(self, val=None): Args: val (object): The value to be moved to the type domain. """ - warnings.warn( - "`plum.Val` is deprecated and will be removed in a future version. " - "Please use `typing.Literal` instead.", - category=DeprecationWarning, - stacklevel=2, - ) if type(self).concrete: if val is not None and type_parameter(self) != val: raise ValueError("The value must be equal to the type parameter.") diff --git a/plum/util.py b/plum/util.py index fb6ad30..18599f0 100644 --- a/plum/util.py +++ b/plum/util.py @@ -1,8 +1,9 @@ import abc import sys -import warnings from typing import Hashable, List, Sequence +from typing_extensions import deprecated + if sys.version_info.minor <= 8: # pragma: specific no cover 3.9 3.10 3.11 from typing import Callable else: # pragma: specific no cover 3.8 @@ -47,6 +48,7 @@ def __init__(self): raise TypeError("`Missing` cannot be instantiated.") +@deprecated("Use `hash(tuple_of_args)` instead.") def multihash(*args: Hashable) -> int: """Multi-argument order-sensitive hash. @@ -56,12 +58,6 @@ def multihash(*args: Hashable) -> int: Returns: int: Hash. """ - warnings.warn( - "The function `multihash` is deprecated and will be removed in a future " - "version. Please use `hash(tuple(*args))` instead.", - DeprecationWarning, - stacklevel=2, - ) return hash(args)