From 4073b824dddaadf99fd0e8be006657f3787b1ba4 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz <vlorentz@softwareheritage.org> Date: Mon, 4 Jul 2022 11:42:24 +0200 Subject: [PATCH] hashutil: Add type annotations to conversion functions --- swh/model/hashutil.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/swh/model/hashutil.py b/swh/model/hashutil.py index 106e7c0c..75d9f8b4 100644 --- a/swh/model/hashutil.py +++ b/swh/model/hashutil.py @@ -56,7 +56,7 @@ import functools import hashlib from io import BytesIO import os -from typing import Callable, Dict, Optional +from typing import Callable, Dict, Optional, Union ALGORITHMS = set(["sha1", "sha256", "sha1_git", "blake2s256", "blake2b512", "md5"]) """Hashing algorithms supported by this module""" @@ -293,7 +293,7 @@ def hash_git_data(data, git_type, base_algo="sha1"): @functools.lru_cache() -def hash_to_hex(hash): +def hash_to_hex(hash: Union[str, bytes]) -> str: """Converts a hash (in hex or bytes form) to its hexadecimal ascii form Args: @@ -309,7 +309,7 @@ def hash_to_hex(hash): @functools.lru_cache() -def hash_to_bytehex(hash): +def hash_to_bytehex(hash: bytes) -> bytes: """Converts a hash to its hexadecimal bytes representation Args: @@ -322,7 +322,7 @@ def hash_to_bytehex(hash): @functools.lru_cache() -def hash_to_bytes(hash): +def hash_to_bytes(hash: Union[str, bytes]) -> bytes: """Converts a hash (in hex or bytes form) to its raw bytes form Args: @@ -338,7 +338,7 @@ def hash_to_bytes(hash): @functools.lru_cache() -def bytehex_to_hash(hex): +def bytehex_to_hash(hex: bytes) -> bytes: """Converts a hexadecimal bytes representation of a hash to that hash Args: -- GitLab