Skip to content

Commit

Permalink
sdk/python: fix type hint for python 3.8 compatibility
Browse files Browse the repository at this point in the history
- Fixes type hints for Python 3.8 compatibility (replace tuple, list, dict with Tuple, List, Dict from typing)

Signed-off-by: Ryan Koo <[email protected]>

changes

Signed-off-by: Ryan Koo <[email protected]>
  • Loading branch information
rkoo19 committed Aug 15, 2024
1 parent 479b4ca commit 18dc104
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 21 deletions.
6 changes: 3 additions & 3 deletions python/aistore/sdk/authn/authn_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

import logging
from typing import Optional, Union
from typing import Optional, Tuple, Union
from aistore.sdk.request_client import RequestClient
from aistore.sdk.const import (
HTTP_METHOD_POST,
Expand All @@ -30,7 +30,7 @@ class AuthNClient:
endpoint (str): AuthN service endpoint URL.
skip_verify (bool, optional): If True, skip SSL certificate verification. Defaults to False.
ca_cert (str, optional): Path to a CA certificate file for SSL verification.
timeout (Union[float, tuple[float, float], None], optional): Request timeout in seconds; a single float
timeout (Union[float, Tuple[float, float], None], optional): Request timeout in seconds; a single float
for both connect/read timeouts (e.g., 5.0), a tuple for separate connect/read timeouts (e.g., (3.0, 10.0)),
or None to disable timeout.
token (str, optional): Authorization token.
Expand All @@ -41,7 +41,7 @@ def __init__(
endpoint: str,
skip_verify: bool = False,
ca_cert: Optional[str] = None,
timeout: Optional[Union[float, tuple[float, float]]] = None,
timeout: Optional[Union[float, Tuple[float, float]]] = None,
token: Optional[str] = None,
):
logger.info("Initializing AuthNClient")
Expand Down
6 changes: 3 additions & 3 deletions python/aistore/sdk/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ def object(self, obj_name: str, props: ObjectProps = None) -> Object:

def objects(
self,
obj_names: list = None,
obj_names: List = None,
obj_range: ObjectRange = None,
obj_template: str = None,
) -> ObjectGroup:
Expand All @@ -861,8 +861,8 @@ def make_request(
self,
method: str,
action: str,
value: dict = None,
params: dict = None,
value: Dict = None,
params: Dict = None,
) -> requests.Response:
"""
Use the bucket's client to make a request to the bucket endpoint on the AIS server
Expand Down
6 changes: 4 additions & 2 deletions python/aistore/sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from __future__ import annotations # pylint: disable=unused-variable

from typing import Optional, Tuple, Union

from aistore.sdk.bucket import Bucket
from aistore.sdk.const import (
PROVIDER_AIS,
Expand All @@ -28,7 +30,7 @@ class Client:
endpoint (str): AIStore endpoint
skip_verify (bool, optional): If True, skip SSL certificate verification. Defaults to False.
ca_cert (str, optional): Path to a CA certificate file for SSL verification.
timeout (Union[float, tuple[float, float], None], optional): Request timeout in seconds; a single float
timeout (Union[float, Tuple[float, float], None], optional): Request timeout in seconds; a single float
for both connect/read timeouts (e.g., 5.0), a tuple for separate connect/read timeouts (e.g., (3.0, 10.0)),
or None to disable timeout.
token (str, optional): Authorization token.
Expand All @@ -39,7 +41,7 @@ def __init__(
endpoint: str,
skip_verify: bool = False,
ca_cert: str = None,
timeout: float | tuple[float, float] | None = None,
timeout: Optional[Union[float, Tuple[float, float]]] = None,
token: str = None,
):
self._request_client = RequestClient(
Expand Down
2 changes: 1 addition & 1 deletion python/aistore/sdk/multiobj/object_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ObjectGroup(AISSource):
def __init__(
self,
bck: "Bucket",
obj_names: list = None,
obj_names: List = None,
obj_range: ObjectRange = None,
obj_template: str = None,
):
Expand Down
8 changes: 4 additions & 4 deletions python/aistore/sdk/request_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
import os
from urllib.parse import urljoin, urlencode
from typing import TypeVar, Type, Any, Dict
from typing import Optional, TypeVar, Tuple, Type, Union, Any, Dict
from requests import session, Session, Response

from aistore.sdk.const import (
Expand All @@ -29,7 +29,7 @@ class RequestClient:
endpoint (str): AIStore endpoint
skip_verify (bool, optional): If True, skip SSL certificate verification. Defaults to False.
ca_cert (str, optional): Path to a CA certificate file for SSL verification.
timeout (Union[float, tuple[float, float], None], optional): Request timeout in seconds; a single float
timeout (Union[float, Tuple[float, float], None], optional): Request timeout in seconds; a single float
for both connect/read timeouts (e.g., 5.0), a tuple for separate connect/read timeouts (e.g., (3.0, 10.0)),
or None to disable timeout.
token (str, optional): Authorization token.
Expand All @@ -40,7 +40,7 @@ def __init__(
endpoint: str,
skip_verify: bool = False,
ca_cert: str = None,
timeout=None,
timeout: Optional[Union[float, Tuple[float, float]]] = None,
token: str = None,
):
self._endpoint = endpoint
Expand Down Expand Up @@ -146,7 +146,7 @@ def request(
method: str,
path: str,
endpoint: str = None,
headers: dict = None,
headers: Dict = None,
**kwargs,
) -> Response:
"""
Expand Down
10 changes: 5 additions & 5 deletions python/aistore/sdk/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ class PrefetchMsg(BaseModel):
API message structure for prefetching objects from remote buckets.
"""

object_selection: dict
object_selection: Dict
continue_on_err: bool
latest: bool
blob_threshold: int = None
Expand All @@ -534,7 +534,7 @@ class TCMultiObj(BaseModel):
to_bck: BucketModel
tc_msg: TCBckMsg = None
continue_on_err: bool
object_selection: dict
object_selection: Dict

def as_dict(self):
dict_rep = self.object_selection
Expand All @@ -557,7 +557,7 @@ class ArchiveMultiObj(BaseModel):
include_source_name = False
allow_append = False
continue_on_err = False
object_selection: dict
object_selection: Dict

def as_dict(self):
dict_rep = self.object_selection
Expand Down Expand Up @@ -729,7 +729,7 @@ class NodeStatsV322(BaseModel):
ais_version: str
build_time: str
k8s_pod_name: str
sys_info: dict
sys_info: Dict
smap_version: str


Expand All @@ -747,7 +747,7 @@ class NodeStats(BaseModel):
ais_version: str
build_time: str
k8s_pod_name: str
sys_info: dict
sys_info: Dict
smap_version: str
reserved1: Optional[str] = ""
reserved2: Optional[str] = ""
Expand Down
8 changes: 5 additions & 3 deletions python/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import io
from pathlib import Path

from typing import Dict, List

from aistore.sdk import Client
from aistore.sdk.const import UTF_ENCODING
from aistore.sdk.errors import ErrBckNotFound
Expand All @@ -16,7 +18,7 @@ def random_string(length: int = 10):
return "".join(random.choices(string.ascii_lowercase, k=length))


def string_to_dict(input_string: str) -> dict:
def string_to_dict(input_string: str) -> Dict:
pairs = input_string.split(", ")
result_dict = {
key_value.split("=")[0]: key_value.split("=")[1] for key_value in pairs
Expand Down Expand Up @@ -104,7 +106,7 @@ def generate_random_content(min_size: int = 1024, max_size: int = 10240) -> byte
size = random.randint(min_size, max_size)
return os.urandom(size)

def generate_files(num_files: int, num_extensions: int, dest_dir: str) -> list:
def generate_files(num_files: int, num_extensions: int, dest_dir: str) -> List:
files_list = []
filenames_list = []

Expand All @@ -124,7 +126,7 @@ def generate_files(num_files: int, num_extensions: int, dest_dir: str) -> list:

return files_list, extension_list

def create_tarballs(min_shard_size: int, dest_dir: str, files_list: list) -> None:
def create_tarballs(min_shard_size: int, dest_dir: str, files_list: List) -> None:
num_input_shards = 0
current_size = 0
dest_dir_path = Path(dest_dir).resolve()
Expand Down

0 comments on commit 18dc104

Please sign in to comment.