From d89f92f5fd971ac99c333fb3ba8680a0b64cf125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Stucke?= Date: Mon, 3 Jun 2024 17:21:37 +0200 Subject: [PATCH] helper/uid: typing fixes (for mypy) --- src/helperFunctions/uid.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/helperFunctions/uid.py b/src/helperFunctions/uid.py index 261395a98d..d62d7643ed 100644 --- a/src/helperFunctions/uid.py +++ b/src/helperFunctions/uid.py @@ -1,17 +1,18 @@ from __future__ import annotations import re -from typing import AnyStr, TypeAlias +from typing import TYPE_CHECKING, Any, AnyStr from helperFunctions.data_conversion import make_bytes from helperFunctions.hash import get_sha256 -UID_REGEX = re.compile(r'[a-f0-9]{64}_[0-9]+') +if TYPE_CHECKING: + from helperFunctions.types import UID -UID: TypeAlias = str +UID_REGEX = re.compile(r'[a-f0-9]{64}_[0-9]+') -def create_uid(input_data: bytes) -> str: +def create_uid(input_data: AnyStr) -> UID: """ generate a UID (unique identifier) SHA256_SIZE for a byte string containing data (e.g. a binary) @@ -23,7 +24,7 @@ def create_uid(input_data: bytes) -> str: return f'{hash_value}_{size}' -def is_uid(input_string: AnyStr) -> bool: +def is_uid(input_string: Any) -> bool: """ Check if a string is a valid UID @@ -38,7 +39,7 @@ def is_uid(input_string: AnyStr) -> bool: return False -def is_list_of_uids(input_list: list[AnyStr] | set[AnyStr]) -> bool: +def is_list_of_uids(input_list: list | set) -> bool: """ Checks if all elements of a list are valid UIDs