Skip to content

Commit

Permalink
Fix and improve type hints (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimes authored Sep 12, 2024
1 parent 49e535e commit cf6f8a8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ This project has adhered to

- Fix a reference leak in the `hash_from_buffer()` function
([#75](https://github.com/hajimes/mmh3/issues/75)).
- Fix type hints.

## [4.1.0] - 2024-01-09

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ complete changelog.

- Fix a reference leak in the `hash_from_buffer()` function
([#75](https://github.com/hajimes/mmh3/issues/75)).
- Fix type hints.

### [4.1.0] - 2024-01-09

Expand Down
60 changes: 36 additions & 24 deletions src/mmh3/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,40 +1,52 @@
# to use list, tuple, dict ... in Python 3.7 and 3.8
from __future__ import annotations

from typing import Protocol, Union, final
from typing import TYPE_CHECKING, Union, final

class IntArrayLike(Protocol):
def __getitem__(self, index) -> int: ...
if TYPE_CHECKING:
from _typeshed import ReadableBuffer

Hashable = Union[bytes, bytearray, memoryview, IntArrayLike]
StrHashable = Union[str, Hashable]
HashableImmutable = Union[str, bytes]
HashableBuffer = Union[HashableImmutable, ReadableBuffer]

def hash(key: StrHashable, seed: int = 0, signed: bool = True) -> int: ...
def hash_from_buffer(key: StrHashable, seed: int = 0, signed: bool = True) -> int: ...
def hash(key: HashableImmutable, seed: int = 0, signed: bool = True) -> int: ...
def hash_from_buffer(
key: HashableBuffer, seed: int = 0, signed: bool = True
) -> int: ...
def hash64(
key: StrHashable, seed: int = 0, x64arch: bool = True, signed: bool = True
key: HashableImmutable, seed: int = 0, x64arch: bool = True, signed: bool = True
) -> tuple[int, int]: ...
def hash128(
key: StrHashable, seed: int = 0, x64arch: bool = True, signed: bool = False
key: HashableImmutable, seed: int = 0, x64arch: bool = True, signed: bool = False
) -> int: ...
def hash_bytes(key: StrHashable, seed: int = 0, x64arch: bool = True) -> bytes: ...
def mmh3_32_digest(key: StrHashable, seed: int = 0) -> bytes: ...
def mmh3_32_sintdigest(key: StrHashable, seed: int = 0) -> int: ...
def mmh3_32_uintdigest(key: StrHashable, seed: int = 0) -> int: ...
def mmh3_x64_128_digest(key: StrHashable, seed: int = 0) -> bytes: ...
def mmh3_x64_128_sintdigest(key: StrHashable, seed: int = 0) -> int: ...
def mmh3_x64_128_uintdigest(key: StrHashable, seed: int = 0) -> int: ...
def mmh3_x64_128_stupledigest(key: StrHashable, seed: int = 0) -> tuple[int, int]: ...
def mmh3_x64_128_utupledigest(key: StrHashable, seed: int = 0) -> tuple[int, int]: ...
def mmh3_x86_128_digest(key: StrHashable, seed: int = 0) -> bytes: ...
def mmh3_x86_128_sintdigest(key: StrHashable, seed: int = 0) -> int: ...
def mmh3_x86_128_uintdigest(key: StrHashable, seed: int = 0) -> int: ...
def mmh3_x86_128_stupledigest(key: StrHashable, seed: int = 0) -> tuple[int, int]: ...
def mmh3_x86_128_utupledigest(key: StrHashable, seed: int = 0) -> tuple[int, int]: ...
def hash_bytes(
key: HashableImmutable, seed: int = 0, x64arch: bool = True
) -> bytes: ...
def mmh3_32_digest(key: HashableBuffer, seed: int = 0) -> bytes: ...
def mmh3_32_sintdigest(key: HashableBuffer, seed: int = 0) -> int: ...
def mmh3_32_uintdigest(key: HashableBuffer, seed: int = 0) -> int: ...
def mmh3_x64_128_digest(key: HashableBuffer, seed: int = 0) -> bytes: ...
def mmh3_x64_128_sintdigest(key: HashableBuffer, seed: int = 0) -> int: ...
def mmh3_x64_128_uintdigest(key: HashableBuffer, seed: int = 0) -> int: ...
def mmh3_x64_128_stupledigest(
key: HashableBuffer, seed: int = 0
) -> tuple[int, int]: ...
def mmh3_x64_128_utupledigest(
key: HashableBuffer, seed: int = 0
) -> tuple[int, int]: ...
def mmh3_x86_128_digest(key: HashableBuffer, seed: int = 0) -> bytes: ...
def mmh3_x86_128_sintdigest(key: HashableBuffer, seed: int = 0) -> int: ...
def mmh3_x86_128_uintdigest(key: HashableBuffer, seed: int = 0) -> int: ...
def mmh3_x86_128_stupledigest(
key: HashableBuffer, seed: int = 0
) -> tuple[int, int]: ...
def mmh3_x86_128_utupledigest(
key: HashableBuffer, seed: int = 0
) -> tuple[int, int]: ...

class Hasher:
def __init__(self, seed: int = 0) -> None: ...
def update(self, input: Hashable) -> None: ...
def update(self, input: ReadableBuffer) -> None: ...
def digest(self) -> bytes: ...
def sintdigest(self) -> int: ...
def uintdigest(self) -> int: ...
Expand Down

0 comments on commit cf6f8a8

Please sign in to comment.