Make library backward compatible: use typing.Union instead of the | operator

This commit is contained in:
2026-04-02 14:28:26 +02:00
parent d88b7228fc
commit 55d3eb8fab
4 changed files with 12 additions and 8 deletions
+3
View File
@@ -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. - `create_file_if_not_exists`: Creates a file if it does not exist.
## Changelog ## Changelog
### Version 0.3.0
- Make library backward compatible: use `typing.Union` instead of the `|` operator
### Version 0.2.5 ### Version 0.2.5
- Update type hint `Sequence` in `jeb_utils.utils.find_nearest_lower_number` to `Sequence[int | float]` - Update type hint `Sequence` in `jeb_utils.utils.find_nearest_lower_number` to `Sequence[int | float]`
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project] [project]
name = "jeb-utils" name = "jeb-utils"
version = "0.2.5" version = "0.3.0"
description = "Common utils for JEB client and server." description = "Common utils for JEB client and server."
dependencies = ["cryptography"] dependencies = ["cryptography"]
license = "Apache-2.0" license = "Apache-2.0"
+4 -3
View File
@@ -15,6 +15,7 @@
import io import io
import re import re
from . import utils from . import utils
from typing import Union
__all__ = [ __all__ = [
'TOPIC_PARTITION_SEPARATOR' '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): def get_next_lower_index_entry(offset: int):
return utils.get_next_lower_integer_multiple(offset, 1024) 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. Validates a topic partition number format.
:param partition_number: The partition number :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`` :return: ``True``, if the partition number is valid, otherwise ``False``
:rtype: bool :rtype: bool
@@ -190,7 +191,7 @@ class AttributesByte:
) )
@classmethod @classmethod
def from_byte(cls, b: bytes | int): def from_byte(cls, b: Union[bytes, int]):
if isinstance(b, int): if isinstance(b, int):
b = bytes([b]) b = bytes([b])
+4 -4
View File
@@ -129,17 +129,17 @@ def get_next_lower_integer_multiple(value: int, multiple: int) -> int:
''' '''
return value - (value % multiple) 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. Finds the nearest lower number to the target from the list.
:param number_list: The list :param number_list: The list
:type number_list: Sequence :type number_list: Sequence[Union[int, float]]
:param target: The target :param target: The target
:type target: int | float :type target: Union[int, float]
:return: The nearest lower number to the target from the list. :return: The nearest lower number to the target from the list.
:rtype: int | float :rtype: Union[int, float]
''' '''
nearest = None nearest = None
for number in number_list: for number in number_list: