Skip to content

Commit

Permalink
use deprecation decorator (#177)
Browse files Browse the repository at this point in the history
Signed-off-by: nstarman <[email protected]>
  • Loading branch information
nstarman authored Jul 3, 2024
1 parent aac1bd3 commit 2528148
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
2 changes: 2 additions & 0 deletions plum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 3 additions & 8 deletions plum/parametric.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -19,7 +20,6 @@
"type_unparametrized",
"kind",
"Kind",
"Val",
]

T = TypeVar("T")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.")
Expand Down
10 changes: 3 additions & 7 deletions plum/util.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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)


Expand Down

0 comments on commit 2528148

Please sign in to comment.