From 0957e7118830b30d705b57deffcadef6baa811c0 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Sun, 24 Sep 2023 21:08:02 +0800 Subject: [PATCH] add type hint for `minio/credentials/credentials.py` (#1298) --- minio/credentials/credentials.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/minio/credentials/credentials.py b/minio/credentials/credentials.py index 4796171f7..3f83a5a32 100644 --- a/minio/credentials/credentials.py +++ b/minio/credentials/credentials.py @@ -15,6 +15,7 @@ # limitations under the License. """Credential definitions to access S3 service.""" +from __future__ import annotations from datetime import datetime, timedelta, timezone @@ -24,8 +25,17 @@ class Credentials: Represents credentials access key, secret key and session token. """ + _access_key: str + _secret_key: str + _session_token: str | None + _expiration: datetime | None + def __init__( - self, access_key, secret_key, session_token=None, expiration=None, + self, + access_key: str, + secret_key: str, + session_token: str | None = None, + expiration: datetime | None = None, ): if not access_key: raise ValueError("Access key must not be empty") @@ -43,21 +53,21 @@ def __init__( self._expiration = expiration @property - def access_key(self): + def access_key(self) -> str: """Get access key.""" return self._access_key @property - def secret_key(self): + def secret_key(self) -> str: """Get secret key.""" return self._secret_key @property - def session_token(self): + def session_token(self) -> str | None: """Get session token.""" return self._session_token - def is_expired(self): + def is_expired(self) -> bool: """Check whether this credentials expired or not.""" return ( self._expiration < (datetime.utcnow() + timedelta(seconds=10))