From 6fd65beefd495bdac778e9bf8d36e07593fb9ce8 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Thu, 31 Aug 2023 21:15:59 +0800 Subject: [PATCH 1/4] add mypy --- Makefile | 3 ++- minio/datatypes.py | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index ee466b8f5..48e3d63e4 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ default: tests getdeps: @echo "Installing required dependencies" - @pip install --user --upgrade autopep8 certifi pytest pylint urllib3 + @pip install --user --upgrade autopep8 certifi pytest pylint urllib3 mypy check: getdeps @echo "Running checks" @@ -11,6 +11,7 @@ check: getdeps @pylint --reports=no --score=no minio/credentials tests/functional @isort --diff . @find . -name "*.py" -exec autopep8 --diff --exit-code {} + + @mypy minio apply: getdeps @isort . diff --git a/minio/datatypes.py b/minio/datatypes.py index 8f86bbb39..a187c7a03 100644 --- a/minio/datatypes.py +++ b/minio/datatypes.py @@ -36,7 +36,7 @@ try: from json.decoder import JSONDecodeError except ImportError: - JSONDecodeError = ValueError + JSONDecodeError = ValueError # type: ignore class Bucket: @@ -411,8 +411,8 @@ def __init__(self, response): self._max_parts = int(self._max_parts) self._is_truncated = findtext(element, "IsTruncated") self._is_truncated = ( - self._is_truncated is not None and - self._is_truncated.lower() == "true" + self._is_truncated is not None and + self._is_truncated.lower() == "true" ) self._parts = [Part.fromxml(tag) for tag in findall(element, "Part")] @@ -574,8 +574,8 @@ def __init__(self, response): self._max_uploads = int(self._max_uploads) self._is_truncated = findtext(element, "IsTruncated") self._is_truncated = ( - self._is_truncated is not None and - self._is_truncated.lower() == "true" + self._is_truncated is not None and + self._is_truncated.lower() == "true" ) self._uploads = [ Upload(tag, self._encoding_type) @@ -673,10 +673,10 @@ def add_equals_condition(self, element, value): element = _trim_dollar(element) if ( element in [ - "success_action_redirect", - "redirect", - "content-length-range", - ] + "success_action_redirect", + "redirect", + "content-length-range", + ] ): raise ValueError(element + " is unsupported for equals condition") if element in _RESERVED_ELEMENTS: @@ -700,8 +700,8 @@ def add_starts_with_condition(self, element, value): if ( element in ["success_action_status", "content-length-range"] or ( - element.startswith("x-amz-") and - not element.startswith("x-amz-meta-") + element.startswith("x-amz-") and + not element.startswith("x-amz-meta-") ) ): raise ValueError( @@ -756,7 +756,7 @@ def form_data(self, creds, region): policy["conditions"] = [[_EQ, "$bucket", self._bucket_name]] for cond_key, conditions in self._conditions.items(): for key, value in conditions.items(): - policy["conditions"].append([cond_key, "$"+key, value]) + policy["conditions"].append([cond_key, "$" + key, value]) if self._lower_limit is not None and self._upper_limit is not None: policy["conditions"].append( ["content-length-range", self._lower_limit, self._upper_limit], From 08719d54ba87b6f6b2eeb4d18c6d4f4a363c6b66 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Thu, 31 Aug 2023 21:18:23 +0800 Subject: [PATCH 2/4] add mypy config --- pyproject.toml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..247b7b4bc --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,5 @@ +[tool.mypy] +python_version = '3.7' +ignore_missing_imports = true +check_untyped_defs = false +disallow_untyped_defs = false From 0757005e8ad210f63a7e0db5b6e80f10f24a2167 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Thu, 31 Aug 2023 21:19:44 +0800 Subject: [PATCH 3/4] update --- minio/datatypes.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/minio/datatypes.py b/minio/datatypes.py index a187c7a03..b13bf234a 100644 --- a/minio/datatypes.py +++ b/minio/datatypes.py @@ -411,8 +411,8 @@ def __init__(self, response): self._max_parts = int(self._max_parts) self._is_truncated = findtext(element, "IsTruncated") self._is_truncated = ( - self._is_truncated is not None and - self._is_truncated.lower() == "true" + self._is_truncated is not None and + self._is_truncated.lower() == "true" ) self._parts = [Part.fromxml(tag) for tag in findall(element, "Part")] @@ -574,8 +574,8 @@ def __init__(self, response): self._max_uploads = int(self._max_uploads) self._is_truncated = findtext(element, "IsTruncated") self._is_truncated = ( - self._is_truncated is not None and - self._is_truncated.lower() == "true" + self._is_truncated is not None and + self._is_truncated.lower() == "true" ) self._uploads = [ Upload(tag, self._encoding_type) @@ -673,10 +673,10 @@ def add_equals_condition(self, element, value): element = _trim_dollar(element) if ( element in [ - "success_action_redirect", - "redirect", - "content-length-range", - ] + "success_action_redirect", + "redirect", + "content-length-range", + ] ): raise ValueError(element + " is unsupported for equals condition") if element in _RESERVED_ELEMENTS: @@ -700,8 +700,8 @@ def add_starts_with_condition(self, element, value): if ( element in ["success_action_status", "content-length-range"] or ( - element.startswith("x-amz-") and - not element.startswith("x-amz-meta-") + element.startswith("x-amz-") and + not element.startswith("x-amz-meta-") ) ): raise ValueError( @@ -756,7 +756,7 @@ def form_data(self, creds, region): policy["conditions"] = [[_EQ, "$bucket", self._bucket_name]] for cond_key, conditions in self._conditions.items(): for key, value in conditions.items(): - policy["conditions"].append([cond_key, "$" + key, value]) + policy["conditions"].append([cond_key, "$"+key, value]) if self._lower_limit is not None and self._upper_limit is not None: policy["conditions"].append( ["content-length-range", self._lower_limit, self._upper_limit], From c606f6bfa7ba6d0ad4f42deeacac395ed140b83c Mon Sep 17 00:00:00 2001 From: Trim21 Date: Mon, 25 Sep 2023 11:20:44 +0800 Subject: [PATCH 4/4] Update Makefile --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 48e3d63e4..ee466b8f5 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ default: tests getdeps: @echo "Installing required dependencies" - @pip install --user --upgrade autopep8 certifi pytest pylint urllib3 mypy + @pip install --user --upgrade autopep8 certifi pytest pylint urllib3 check: getdeps @echo "Running checks" @@ -11,7 +11,6 @@ check: getdeps @pylint --reports=no --score=no minio/credentials tests/functional @isort --diff . @find . -name "*.py" -exec autopep8 --diff --exit-code {} + - @mypy minio apply: getdeps @isort .