Skip to content

Commit f9d194c

Browse files
kurodo3[bot]eywalker
authored andcommitted
refactor: replace private hashlib._Hash with local _Hasher Protocol (PLT-1734)
1 parent cb66bfa commit f9d194c

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/starfix/arrow_digester.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@
1010
import json
1111
import struct
1212
from collections import OrderedDict
13-
from typing import TYPE_CHECKING
13+
from typing import TYPE_CHECKING, Protocol
1414

1515
if TYPE_CHECKING:
16-
from hashlib import _Hash
17-
1816
import pyarrow as pa
1917

18+
19+
class _Hasher(Protocol):
20+
"""Minimal protocol for a hash accumulator (e.g. ``hashlib.sha256()``)."""
21+
22+
def update(self, data: bytes | bytearray, /) -> None: ...
23+
24+
2025
VERSION_BYTES = b"\x00\x00\x01"
2126
DELIMITER = "/"
2227

@@ -256,7 +261,7 @@ def _collect_nested_field_metadata(
256261
return dict(sorted(result.items()))
257262

258263

259-
def _update_metadata_hash(hasher: _Hash, schema: pa.Schema) -> None:
264+
def _update_metadata_hash(hasher: _Hasher, schema: pa.Schema) -> None:
260265
"""Feed Phase 2 metadata JSON into ``hasher`` (only when metadata is present).
261266
262267
Builds a compact JSON string of the form:

0 commit comments

Comments
 (0)