Skip to content

Commit

Permalink
feat: deprecate multihash (#175)
Browse files Browse the repository at this point in the history
Signed-off-by: nstarman <[email protected]>
  • Loading branch information
nstarman authored Jun 28, 2024
1 parent 6c695e9 commit 0f5e573
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions plum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
from .type import resolve_type_hint
from .util import * # noqa: F401, F403

# Deprecated
from .util import multihash # noqa: F401, F403

# Ensure that type checking is always entirely correct! The default O(1) strategy
# is super fast, but might yield unpredictable dispatch behaviour. The O(n) strategy
# actually is not yet available, but we can already opt in to use it.
Expand Down
4 changes: 2 additions & 2 deletions plum/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .repr import repr_short, rich_repr
from .type import is_faithful, resolve_type_hint
from .typing import get_type_hints
from .util import Comparable, Missing, TypeHint, multihash, wrap_lambda
from .util import Comparable, Missing, TypeHint, wrap_lambda

__all__ = ["Signature", "append_default_args"]

Expand Down Expand Up @@ -131,7 +131,7 @@ def __eq__(self, other):
return False

def __hash__(self):
return multihash(Signature, *self.types, self.varargs)
return hash((Signature, *self.types, self.varargs))

def expand_varargs(self, n: int) -> Tuple[TypeHint, ...]:
"""Expand variable arguments.
Expand Down
12 changes: 9 additions & 3 deletions plum/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import abc
import sys
from typing import List, Sequence
import warnings
from typing import Hashable, List, Sequence

if sys.version_info.minor <= 8: # pragma: specific no cover 3.9 3.10 3.11
from typing import Callable
Expand All @@ -11,7 +12,6 @@
"Callable",
"TypeHint",
"Missing",
"multihash",
"Comparable",
"wrap_lambda",
"is_in_class",
Expand Down Expand Up @@ -47,7 +47,7 @@ def __init__(self):
raise TypeError("`Missing` cannot be instantiated.")


def multihash(*args):
def multihash(*args: Hashable) -> int:
"""Multi-argument order-sensitive hash.
Args:
Expand All @@ -56,6 +56,12 @@ def multihash(*args):
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 0f5e573

Please sign in to comment.