From 06ea18f18dc1b59bc65fd7ee6507e533ae2bc70d Mon Sep 17 00:00:00 2001 From: Alexey Timin Date: Wed, 6 Mar 2024 23:03:24 +0100 Subject: [PATCH] fix python 3.8 compatibility --- reduct/bucket.py | 10 +++++----- reduct/record.py | 13 +++++++++++-- reduct/time.py | 3 ++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/reduct/bucket.py b/reduct/bucket.py index 8249c60..3922381 100644 --- a/reduct/bucket.py +++ b/reduct/bucket.py @@ -178,7 +178,7 @@ async def remove_entry(self, entry_name: str): async def read( self, entry_name: str, - timestamp: Optional[int | datetime | float | str] = None, + timestamp: Optional[Union[int, datetime, float, str]] = None, head: bool = False, ) -> Record: """ @@ -209,7 +209,7 @@ async def write( self, entry_name: str, data: Union[bytes, AsyncIterator[bytes]], - timestamp: Optional[int | datetime | float | str] = None, + timestamp: Optional[Union[int, datetime, float, str]] = None, content_length: Optional[int] = None, **kwargs, ): @@ -306,8 +306,8 @@ async def iter_body(): async def query( self, entry_name: str, - start: Optional[int | datetime | float | str] = None, - stop: Optional[int | datetime | float | str] = None, + start: Optional[Union[int, datetime, float, str]] = None, + stop: Optional[Union[int, datetime, float, str]] = None, ttl: Optional[int] = None, **kwargs, ) -> AsyncIterator[Record]: @@ -375,7 +375,7 @@ async def get_full_info(self) -> BucketFullInfo: async def subscribe( self, entry_name: str, - start: Optional[int | datetime | float | str] = None, + start: Optional[Union[int, datetime, float, str]] = None, poll_interval=1.0, **kwargs, ) -> AsyncIterator[Record]: diff --git a/reduct/record.py b/reduct/record.py index a4027a0..c50c242 100644 --- a/reduct/record.py +++ b/reduct/record.py @@ -4,7 +4,16 @@ from dataclasses import dataclass from datetime import datetime from functools import partial -from typing import Dict, Callable, AsyncIterator, Awaitable, Optional, List, Tuple +from typing import ( + Dict, + Callable, + AsyncIterator, + Awaitable, + Optional, + List, + Tuple, + Union, +) from aiohttp import ClientResponse @@ -47,7 +56,7 @@ def __init__(self): def add( self, - timestamp: int | datetime | float | str, + timestamp: Union[int, datetime, float, str], data: bytes, content_type: Optional[str] = None, labels: Optional[Dict[str, str]] = None, diff --git a/reduct/time.py b/reduct/time.py index 5236cc4..1a3c56f 100644 --- a/reduct/time.py +++ b/reduct/time.py @@ -1,11 +1,12 @@ """Helper functions for time-related operations.""" from datetime import datetime +from typing import Union TIME_PRECISION = 1_000_000 -def unix_timestamp_from_any(timestamp: int | datetime | float | str) -> int: +def unix_timestamp_from_any(timestamp: Union[int, datetime, float, str]) -> int: """Convert timestamp to UNIX timestamp in microseconds Args: timestamp (int | datetime | float | str): int (UNIX timestamp in microseconds),