Files
Matt HauffandGitHub 40db4635a8 [LABS-245] Enable PEP604 Ruff rules (#20269)
* Enable PEP604 Ruff rules

* Fix harcoded signature in test

* Hack CLVMStreamable test with note to fast follow
2025-11-18 12:34:00 -08:00

32 lines
814 B
Python

# Package: utils
from __future__ import annotations
from hashlib import sha256
from typing import Literal, SupportsBytes, cast, overload
from chia_rs.sized_bytes import bytes32
@overload
def std_hash(b: bytes | SupportsBytes) -> bytes32: ...
@overload
def std_hash(b: bytes | SupportsBytes, skip_bytes_conversion: Literal[False]) -> bytes32: ...
@overload
def std_hash(b: bytes, skip_bytes_conversion: Literal[True]) -> bytes32: ...
def std_hash(b: bytes | SupportsBytes, skip_bytes_conversion: bool = False) -> bytes32:
"""
The standard hash used in many places.
"""
if skip_bytes_conversion:
# casting for hinting based on above overloads constraining the type
return bytes32(sha256(cast(bytes, b)).digest())
else:
return bytes32(sha256(bytes(b)).digest())