Skip to content

Commit 15c9699

Browse files
authored
Enable mypy check (#1376)
Signed-off-by: Bala.FA <[email protected]>
1 parent cff578e commit 15c9699

File tree

6 files changed

+24
-18
lines changed

6 files changed

+24
-18
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ default: tests
33

44
getdeps:
55
@echo "Installing required dependencies"
6-
@pip install --user --upgrade autopep8 certifi pytest pylint urllib3 argon2-cffi pycryptodome typing-extensions
6+
@pip install --user --upgrade autopep8 certifi pytest pylint urllib3 argon2-cffi pycryptodome typing-extensions mypy
77

88
check: getdeps
99
@echo "Running checks"
1010
@pylint --reports=no --score=no --disable=R0401,R0801 minio/*py
1111
@pylint --reports=no --score=no minio/credentials tests/functional
1212
@isort --diff .
1313
@find . -name "*.py" -exec autopep8 --diff --exit-code {} +
14+
@mypy minio
1415

1516
apply: getdeps
1617
@isort .

minio/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ def get_object(
12241224
check_non_empty_string(object_name)
12251225
check_ssec(ssec)
12261226

1227-
headers = ssec.headers() if ssec else {}
1227+
headers = cast(DictType, ssec.headers() if ssec else {})
12281228
headers.update(request_headers or {})
12291229

12301230
if offset or length:
@@ -3171,7 +3171,7 @@ def _list_multipart_uploads(
31713171
"GET",
31723172
bucket_name,
31733173
query_params=cast(DictType, query_params),
3174-
headers=cast(DictType | None, extra_headers),
3174+
headers=cast(Union[DictType, None], extra_headers),
31753175
)
31763176
return ListMultipartUploadsResult(response)
31773177

@@ -3214,6 +3214,6 @@ def _list_parts(
32143214
bucket_name,
32153215
object_name=object_name,
32163216
query_params=cast(DictType, query_params),
3217-
headers=cast(DictType | None, extra_headers),
3217+
headers=cast(Union[DictType, None], extra_headers),
32183218
)
32193219
return ListPartsResult(response)

minio/helpers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,10 @@ def md5sum_hash(data: str | bytes | None) -> str | None:
302302

303303
# indicate md5 hashing algorithm is not used in a security context.
304304
# Refer https://bugs.python.org/issue9216 for more information.
305-
hasher = hashlib.new("md5", usedforsecurity=False)
305+
hasher = hashlib.new( # type: ignore[call-arg]
306+
"md5",
307+
usedforsecurity=False,
308+
)
306309
hasher.update(data.encode() if isinstance(data, str) else data)
307310
md5sum = base64.b64encode(hasher.digest())
308311
return md5sum.decode() if isinstance(md5sum, bytes) else md5sum

minio/minioadmin.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import os
2525
from datetime import timedelta
2626
from enum import Enum
27-
from typing import TextIO
27+
from typing import TextIO, Tuple, cast
2828
from urllib.parse import urlunsplit
2929

3030
import certifi
@@ -40,7 +40,7 @@
4040
from .crypto import decrypt, encrypt
4141
from .datatypes import PeerInfo, PeerSite, SiteReplicationStatusOptions
4242
from .error import MinioAdminException
43-
from .helpers import (_DEFAULT_USER_AGENT, _REGION_REGEX, _parse_url,
43+
from .helpers import (_DEFAULT_USER_AGENT, _REGION_REGEX, DictType, _parse_url,
4444
headers_to_strings, queryencode, sha256_hash,
4545
url_replace)
4646
from .signer import sign_v4_s3
@@ -149,8 +149,7 @@ def _url_open(
149149
self,
150150
method: str,
151151
command: CommandType,
152-
query_params:
153-
dict[str, str | list[str] | tuple[str]] | None = None,
152+
query_params: DictType | None = None,
154153
body: bytes | None = None,
155154
preload_content: bool = True,
156155
) -> BaseHTTPResponse:
@@ -169,7 +168,7 @@ def _url_open(
169168

170169
content_sha256 = sha256_hash(body)
171170
date = time.utcnow()
172-
headers: dict[str, str | list[str] | tuple[str]] = {
171+
headers: DictType = {
173172
"Host": url.netloc,
174173
"User-Agent": self._user_agent,
175174
"x-amz-date": time.to_amz_date(date),
@@ -239,7 +238,7 @@ def _url_open(
239238
if response.status in [200, 204, 206]:
240239
return response
241240

242-
raise MinioAdminException(response.status, response.data.decode())
241+
raise MinioAdminException(str(response.status), response.data.decode())
243242

244243
def set_app_info(self, app_name: str, app_version: str):
245244
"""
@@ -472,7 +471,7 @@ def policy_set(
472471
response = self._url_open(
473472
"PUT",
474473
_COMMAND.SET_USER_OR_GROUP_POLICY,
475-
query_params={"userOrGroup": user or group,
474+
query_params={"userOrGroup": cast(str, user or group),
476475
"isGroup": "true" if group else "false",
477476
"policyName": policy_name},
478477
)
@@ -585,7 +584,10 @@ def config_restore(self, restore_id: str) -> str:
585584
)
586585
return response.data.decode()
587586

588-
def profile_start(self, profilers: tuple[str] = ()) -> str:
587+
def profile_start(
588+
self,
589+
profilers: tuple[str] = cast(Tuple[str], ()),
590+
) -> str:
589591
"""Runs a system profile"""
590592
response = self._url_open(
591593
"POST",
@@ -607,7 +609,7 @@ def kms_key_create(self, key: str | None = None) -> str:
607609
response = self._url_open(
608610
"POST",
609611
_COMMAND.CREATE_KMS_KEY,
610-
query_params={"key-id": key},
612+
query_params={"key-id": key or ""},
611613
)
612614
return response.data.decode()
613615

@@ -645,7 +647,7 @@ def get_site_replication_status(
645647
response = self._url_open(
646648
"GET",
647649
_COMMAND.SITE_REPLICATION_STATUS,
648-
query_params=options.to_query_params(),
650+
query_params=cast(DictType, options.to_query_params()),
649651
)
650652
return response.data.decode()
651653

@@ -668,9 +670,9 @@ def remove_site_replication(
668670
"""Remove given sites or all sites from site replication."""
669671
data = {}
670672
if all_sites:
671-
data.update({"all": True})
673+
data.update({"all": "True"})
672674
elif sites:
673-
data.update({"sites": sites})
675+
data.update({"sites": sites or ""})
674676
else:
675677
raise ValueError("either sites or all flag must be given")
676678
body = json.dumps(data).encode()

minio/py.typed

Whitespace-only changes.

minio/time.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from datetime import datetime, timezone
2323

2424
try:
25-
from datetime import UTC
25+
from datetime import UTC # type: ignore[attr-defined]
2626
_UTC_IMPORTED = True
2727
except ImportError:
2828
_UTC_IMPORTED = False

0 commit comments

Comments
 (0)