From 55d3eb8fab40957ac1667dfd9846d08a361d5c2e Mon Sep 17 00:00:00 2001 From: Jakob Scheid Date: Thu, 2 Apr 2026 14:28:26 +0200 Subject: [PATCH] Make library backward compatible: use typing.Union instead of the | operator --- README.md | 3 +++ pyproject.toml | 2 +- src/jeb_utils/jeb_utils.py | 7 ++++--- src/jeb_utils/utils.py | 8 ++++---- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 90a4563..95949b2 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,9 @@ pip install jeb-utils --index-url https://repo.jcloud-services.ddns.net/simple/ - `create_file_if_not_exists`: Creates a file if it does not exist. ## Changelog +### Version 0.3.0 +- Make library backward compatible: use `typing.Union` instead of the `|` operator + ### Version 0.2.5 - Update type hint `Sequence` in `jeb_utils.utils.find_nearest_lower_number` to `Sequence[int | float]` diff --git a/pyproject.toml b/pyproject.toml index 52eb6d3..6c88000 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "jeb-utils" -version = "0.2.5" +version = "0.3.0" description = "Common utils for JEB client and server." dependencies = ["cryptography"] license = "Apache-2.0" \ No newline at end of file diff --git a/src/jeb_utils/jeb_utils.py b/src/jeb_utils/jeb_utils.py index d48b6f4..296d2d8 100644 --- a/src/jeb_utils/jeb_utils.py +++ b/src/jeb_utils/jeb_utils.py @@ -15,6 +15,7 @@ import io import re from . import utils +from typing import Union __all__ = [ 'TOPIC_PARTITION_SEPARATOR' @@ -63,12 +64,12 @@ def format_topic_partitions(topic_name: str, partitions: set) -> list: def get_next_lower_index_entry(offset: int): return utils.get_next_lower_integer_multiple(offset, 1024) -def validate_topic_partition(partition_number: str | int) -> bool: +def validate_topic_partition(partition_number: Union[str, int]) -> bool: ''' Validates a topic partition number format. :param partition_number: The partition number - :type partition_number: str | int + :type partition_number: Union[str, int] :return: ``True``, if the partition number is valid, otherwise ``False`` :rtype: bool @@ -190,7 +191,7 @@ class AttributesByte: ) @classmethod - def from_byte(cls, b: bytes | int): + def from_byte(cls, b: Union[bytes, int]): if isinstance(b, int): b = bytes([b]) diff --git a/src/jeb_utils/utils.py b/src/jeb_utils/utils.py index 29c7b40..c5a519d 100644 --- a/src/jeb_utils/utils.py +++ b/src/jeb_utils/utils.py @@ -129,17 +129,17 @@ def get_next_lower_integer_multiple(value: int, multiple: int) -> int: ''' return value - (value % multiple) -def find_nearest_lower_number(number_list: Sequence[int | float], target: int | float) -> int | float: +def find_nearest_lower_number(number_list: Sequence[Union[int, float]], target: Union[int, float]) -> Union[int, float]: ''' Finds the nearest lower number to the target from the list. :param number_list: The list - :type number_list: Sequence + :type number_list: Sequence[Union[int, float]] :param target: The target - :type target: int | float + :type target: Union[int, float] :return: The nearest lower number to the target from the list. - :rtype: int | float + :rtype: Union[int, float] ''' nearest = None for number in number_list: