From ed0c8bf78ff71daef20ada18b7ec8d8e3bab79e6 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Sun, 24 Sep 2023 23:21:57 +0800 Subject: [PATCH 1/2] add type hint for `Minio.put_object` (#1301) --- minio/api.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/minio/api.py b/minio/api.py index d9141e732..027757d30 100644 --- a/minio/api.py +++ b/minio/api.py @@ -21,7 +21,7 @@ Simple Storage Service (aka S3) client to perform bucket and object operations. """ -from __future__ import absolute_import +from __future__ import absolute_import, annotations import itertools import os @@ -31,6 +31,7 @@ from io import BytesIO from random import random from threading import Thread +from typing import BinaryIO from urllib.parse import urlunsplit from xml.etree import ElementTree as ET @@ -61,7 +62,7 @@ from .retention import Retention from .select import SelectObjectReader, SelectRequest from .signer import presign_v4, sign_v4_s3 -from .sse import SseCustomerKey +from .sse import Sse, SseCustomerKey from .sseconfig import SSEConfig from .tagging import Tagging from .versioningconfig import VersioningConfig @@ -1604,11 +1605,22 @@ def _upload_part_task(self, args): """Upload_part task for ThreadPool.""" return args[5], self._upload_part(*args) - def put_object(self, bucket_name, object_name, data, length, - content_type="application/octet-stream", - metadata=None, sse=None, progress=None, - part_size=0, num_parallel_uploads=3, - tags=None, retention=None, legal_hold=False): + def put_object( + self, + bucket_name: str, + object_name: str, + data: BinaryIO, + length: int, + content_type: str = "application/octet-stream", + metadata: dict[str, str] | None = None, + sse: Sse | None = None, + progress: Thread | None = None, + part_size: int = 0, + num_parallel_uploads: int = 3, + tags: Tags | None = None, + retention: Retention | None = None, + legal_hold: bool = False + ) -> ObjectWriteResult: """ Uploads data from a stream to an object in a bucket. From 1d70730a3dc6fdbd4ce205c33c3074047cf736b8 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Sun, 24 Sep 2023 23:23:05 +0800 Subject: [PATCH 2/2] add type hint for Minio.get_object (#1300) --- minio/api.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/minio/api.py b/minio/api.py index 027757d30..36d961829 100644 --- a/minio/api.py +++ b/minio/api.py @@ -1078,9 +1078,17 @@ def fget_object(self, bucket_name, object_name, file_path, response.close() response.release_conn() - def get_object(self, bucket_name, object_name, offset=0, length=0, - request_headers=None, ssec=None, version_id=None, - extra_query_params=None): + def get_object( + self, + bucket_name: str, + object_name: str, + offset: int = 0, + length: int = 0, + request_headers: dict[str, str] | None = None, + ssec: SseCustomerKey | None = None, + version_id: str | None = None, + extra_query_params: dict[str, str] | None = None + ) -> urllib3.BaseHTTPResponse: """ Get data of an object. Returned response should be closed after use to release network resources. To reuse the connection, it's required to