typing cleanup

This commit is contained in:
Jonathan Wren 2022-10-01 10:17:44 -07:00
parent 7c6e34deda
commit 62b733729e
4 changed files with 10 additions and 9 deletions

View file

@ -12,8 +12,9 @@ from jrnl.messages import MsgText
class BaseEncryption(ABC): class BaseEncryption(ABC):
_encoding: str _encoding: str
_journal_name: str _journal_name: str
_config: dict
def __init__(self, journal_name, config): def __init__(self, journal_name: str, config: dict):
self._encoding = "utf-8" self._encoding = "utf-8"
self._journal_name = journal_name self._journal_name = journal_name
self._config = config self._config = config

View file

@ -11,7 +11,7 @@ class BasePasswordEncryption(BaseEncryption):
_max_attempts: int _max_attempts: int
_password: str _password: str
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self._attempts = 0 self._attempts = 0
self._max_attempts = 3 self._max_attempts = 3
@ -23,11 +23,11 @@ class BasePasswordEncryption(BaseEncryption):
self.password = keyring_pw self.password = keyring_pw
@property @property
def password(self): def password(self) -> str:
return self._password return self._password
@password.setter @password.setter
def password(self, value): def password(self, value: str) -> None:
self._password = value self._password = value
def encrypt(self, text: str) -> str: def encrypt(self, text: str) -> str:
@ -43,7 +43,7 @@ class BasePasswordEncryption(BaseEncryption):
return result return result
def _prompt_password(self): def _prompt_password(self) -> None:
self._attempts, self.password = prompt_password( self._attempts, self.password = prompt_password(
self._attempts, self._max_attempts self._attempts, self._max_attempts
) )

View file

@ -38,7 +38,7 @@ def list_journals(configuration):
return result return result
def print_msg(msg: Message, **kwargs) -> Union[None, str]: def print_msg(msg: Message, **kwargs) -> None | str:
"""Helper function to print a single message""" """Helper function to print a single message"""
kwargs["style"] = msg.style kwargs["style"] = msg.style
return print_msgs([msg], **kwargs) return print_msgs([msg], **kwargs)
@ -50,7 +50,7 @@ def print_msgs(
style: MsgStyle = MsgStyle.NORMAL, style: MsgStyle = MsgStyle.NORMAL,
get_input: bool = False, get_input: bool = False,
hide_input: bool = False, hide_input: bool = False,
) -> Union[None, str]: ) -> None | str:
# Same as print_msg, but for a list # Same as print_msg, but for a list
text = Text("", end="") text = Text("", end="")
kwargs = style.decoration.args kwargs = style.decoration.args

View file

@ -43,7 +43,7 @@ def create_password(journal_name: str) -> str:
return pw return pw
def prompt_password(attempts: int, max_attempts: int) -> tuple[int, str | None]: def prompt_password(attempts: int, max_attempts: int) -> tuple[int, str]:
if attempts >= max_attempts: if attempts >= max_attempts:
raise JrnlException(Message(MsgText.PasswordMaxTriesExceeded, MsgStyle.ERROR)) raise JrnlException(Message(MsgText.PasswordMaxTriesExceeded, MsgStyle.ERROR))
@ -55,7 +55,7 @@ def prompt_password(attempts: int, max_attempts: int) -> tuple[int, str | None]:
Message(MsgText.Password, MsgStyle.PROMPT), Message(MsgText.Password, MsgStyle.PROMPT),
get_input=True, get_input=True,
hide_input=True, hide_input=True,
) ) or ""
def yesno(prompt: Message, default: bool = True) -> bool: def yesno(prompt: Message, default: bool = True) -> bool: