Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some additional type annotations #1324

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions minio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
import os
import platform
import tarfile
from datetime import timedelta
from collections.abc import Mapping, MutableMapping
from datetime import datetime, timedelta
from io import BytesIO
from random import random
from threading import Thread
Expand Down Expand Up @@ -1096,10 +1097,10 @@ def get_object(
object_name: str,
offset: int = 0,
length: int = 0,
request_headers: dict[str, str] | None = None,
request_headers: Mapping[str, str] | None = None,
ssec: SseCustomerKey | None = None,
version_id: str | None = None,
extra_query_params: dict[str, str] | None = None
extra_query_params: MutableMapping[str, str] | None = None
) -> urllib3.BaseHTTPResponse:
"""
Get data of an object. Returned response should be closed after use to
Expand Down Expand Up @@ -1543,7 +1544,7 @@ def compose_object( # pylint: disable=too-many-branches
)
raise exc

def _abort_multipart_upload(self, bucket_name, object_name, upload_id):
def _abort_multipart_upload(self, bucket_name: str, object_name: str, upload_id: str):
"""Execute AbortMultipartUpload S3 API."""
self._execute(
"DELETE",
Expand Down Expand Up @@ -1575,7 +1576,11 @@ def _complete_multipart_upload(
)
return CompleteMultipartUploadResult(response)

def _create_multipart_upload(self, bucket_name, object_name, headers):
def _create_multipart_upload(
self, bucket_name: str,
object_name: str,
headers: MutableMapping[str, str]
):
"""Execute CreateMultipartUpload S3 API."""
if not headers.get("Content-Type"):
headers["Content-Type"] = "application/octet-stream"
Expand Down Expand Up @@ -1632,7 +1637,7 @@ def put_object(
data: BinaryIO,
length: int,
content_type: str = "application/octet-stream",
metadata: dict[str, str] | None = None,
metadata: Mapping[str, str] | None = None,
sse: Sse | None = None,
progress: Thread | None = None,
part_size: int = 0,
Expand Down Expand Up @@ -1857,8 +1862,14 @@ def list_objects(self, bucket_name, prefix=None, recursive=False,
fetch_owner=fetch_owner,
)

def stat_object(self, bucket_name, object_name, ssec=None, version_id=None,
extra_query_params=None):
def stat_object(
self,
bucket_name: str,
object_name: str,
ssec: SseCustomerKey | None = None,
version_id: str | None = None,
extra_query_params: MutableMapping[str, str] | None = None
):
"""
Get object information and metadata of an object.

Expand Down Expand Up @@ -2040,10 +2051,17 @@ def remove_objects(self, bucket_name, delete_object_list,
if error.code != "NoSuchVersion":
yield error

def get_presigned_url(self, method, bucket_name, object_name,
expires=timedelta(days=7), response_headers=None,
request_date=None, version_id=None,
extra_query_params=None):
def get_presigned_url(
self,
method: str,
bucket_name: str,
object_name: str,
expires: timedelta = timedelta(days=7),
response_headers: Mapping[str, str] | None = None,
request_date: datetime | None = None,
version_id: str | None = None,
extra_query_params: MutableMapping[str, str] | None = None
):
"""
Get presigned URL of an object for HTTP method, expiry time and custom
request parameters.
Expand Down
29 changes: 15 additions & 14 deletions minio/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import datetime
import json
from collections import OrderedDict
from collections.abc import Mapping
from urllib.parse import unquote_plus
from xml.etree import ElementTree as ET

Expand Down Expand Up @@ -126,72 +127,72 @@ def __init__(self, # pylint: disable=too-many-arguments
self._is_delete_marker = is_delete_marker

@property
def bucket_name(self):
def bucket_name(self) -> str:
"""Get bucket name."""
return self._bucket_name

@property
def object_name(self):
def object_name(self) -> str:
"""Get object name."""
return self._object_name

@property
def is_dir(self):
def is_dir(self) -> bool:
"""Get whether this key is a directory."""
return self._object_name.endswith("/")

@property
def last_modified(self):
def last_modified(self) -> datetime.datetime | None:
"""Get last modified time."""
return self._last_modified

@property
def etag(self):
def etag(self) -> str | None:
"""Get etag."""
return self._etag

@property
def size(self):
def size(self) -> int | None:
"""Get size."""
return self._size

@property
def metadata(self):
def metadata(self) -> Mapping[str, str] | None:
"""Get metadata."""
return self._metadata

@property
def version_id(self):
def version_id(self) -> str | None:
"""Get version ID."""
return self._version_id

@property
def is_latest(self):
def is_latest(self) -> bool | None:
"""Get is-latest flag."""
return self._is_latest

@property
def storage_class(self):
def storage_class(self) -> str | None:
"""Get storage class."""
return self._storage_class

@property
def owner_id(self):
def owner_id(self) -> str | None:
"""Get owner ID."""
return self._owner_id

@property
def owner_name(self):
def owner_name(self) -> str | None:
"""Get owner name."""
return self._owner_name

@property
def is_delete_marker(self):
def is_delete_marker(self) -> bool:
"""Get whether this key is a delete marker."""
return self._is_delete_marker

@property
def content_type(self):
def content_type(self) -> str | None:
"""Get content type."""
return self._content_type

Expand Down
8 changes: 5 additions & 3 deletions minio/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

from xml.etree import ElementTree as ET

from urllib3 import HTTPResponse

from .xml import findtext


Expand Down Expand Up @@ -103,17 +105,17 @@ def __reduce__(self):
self._bucket_name, self._object_name)

@property
def code(self):
def code(self) -> str:
"""Get S3 error code."""
return self._code

@property
def message(self):
def message(self) -> str:
"""Get S3 error message."""
return self._message

@property
def response(self):
def response(self) -> HTTPResponse:
"""Get HTTP response."""
return self._response

Expand Down
Loading