Skip to content

Commit

Permalink
helper/uid: typing fixes (for mypy)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstucke committed Nov 26, 2024
1 parent 0dd11c4 commit d89f92f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/helperFunctions/uid.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d89f92f

Please sign in to comment.