Make library backward compatible: use typing.Union instead of the | operator
This commit is contained in:
@@ -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]`
|
||||
|
||||
|
||||
+1
-1
@@ -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"
|
||||
@@ -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])
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user