From 875035c33dbb8001749f03c02aab0f1964ca9798 Mon Sep 17 00:00:00 2001 From: David Hotham Date: Sat, 10 Aug 2024 13:23:42 +0100 Subject: [PATCH] add a couple of type annotations --- keyring/credentials.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/keyring/credentials.py b/keyring/credentials.py index 713a9dbe..482220ae 100644 --- a/keyring/credentials.py +++ b/keyring/credentials.py @@ -1,32 +1,34 @@ import abc import os +from __future__ import annotations + class Credential(metaclass=abc.ABCMeta): """Abstract class to manage credentials""" @abc.abstractproperty - def username(self): + def username(self) -> str | None: return None @abc.abstractproperty - def password(self): + def password(self) -> str | None: return None class SimpleCredential(Credential): """Simple credentials implementation""" - def __init__(self, username, password): + def __init__(self, username: str | None, password: str | None): self._username = username self._password = password @property - def username(self): + def username(self) -> str | None: return self._username @property - def password(self): + def password(self) -> str | None: return self._password @@ -47,14 +49,14 @@ class EnvironCredential(Credential): False """ - def __init__(self, user_env_var, pwd_env_var): + def __init__(self, user_env_var: str, pwd_env_var: str): self.user_env_var = user_env_var self.pwd_env_var = pwd_env_var def __eq__(self, other: object) -> bool: return vars(self) == vars(other) - def _get_env(self, env_var): + def _get_env(self, env_var: str) -> str: """Helper to read an environment variable""" value = os.environ.get(env_var) if not value: @@ -62,9 +64,9 @@ def _get_env(self, env_var): return value @property - def username(self): + def username(self) -> str: return self._get_env(self.user_env_var) @property - def password(self): + def password(self) -> str: return self._get_env(self.pwd_env_var)