Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and improve type hints #76

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading