diff --git a/jrnl/EncryptedJournal.py b/jrnl/EncryptedJournal.py index 8b742d29..74fdbdf8 100644 --- a/jrnl/EncryptedJournal.py +++ b/jrnl/EncryptedJournal.py @@ -2,6 +2,7 @@ # License: https://www.gnu.org/licenses/gpl-3.0.html import base64 +import contextlib import hashlib import logging import os @@ -202,10 +203,9 @@ def set_keychain(journal_name, password): import keyring if password is None: - try: + cm = contextlib.suppress(keyring.errors.KeyringError) + with cm: keyring.delete_password("jrnl", journal_name) - except keyring.errors.KeyringError: - pass else: try: keyring.set_password("jrnl", journal_name, password) diff --git a/jrnl/messages/__init__.py b/jrnl/messages/__init__.py index 381ee332..602267e6 100644 --- a/jrnl/messages/__init__.py +++ b/jrnl/messages/__init__.py @@ -1,10 +1,6 @@ # Copyright © 2012-2022 jrnl contributors # License: https://www.gnu.org/licenses/gpl-3.0.html -from jrnl.messages.Message import Message -from jrnl.messages.MsgStyle import MsgStyle -from jrnl.messages.MsgText import MsgText - -Message = Message -MsgStyle = MsgStyle -MsgText = MsgText +from jrnl.messages.Message import Message # noqa: F401 +from jrnl.messages.MsgStyle import MsgStyle # noqa: F401 +from jrnl.messages.MsgText import MsgText # noqa: F401 diff --git a/jrnl/output.py b/jrnl/output.py index 2db0362e..f4e80ce1 100644 --- a/jrnl/output.py +++ b/jrnl/output.py @@ -2,7 +2,7 @@ # License: https://www.gnu.org/licenses/gpl-3.0.html import textwrap -from typing import Union +from typing import Optional from rich.console import Console from rich.text import Text @@ -69,7 +69,7 @@ def list_journals(configuration, format=None): return journal_list_to_stdout(journal_list) -def print_msg(msg: Message, **kwargs) -> Union[None, str]: +def print_msg(msg: Message, **kwargs) -> Optional[str]: """Helper function to print a single message""" kwargs["style"] = msg.style return print_msgs([msg], **kwargs) @@ -81,7 +81,7 @@ def print_msgs( style: MsgStyle = MsgStyle.NORMAL, get_input: bool = False, hide_input: bool = False, -) -> Union[None, str]: +) -> Optional[str]: # Same as print_msg, but for a list text = Text("", end="") kwargs = style.decoration.args diff --git a/jrnl/plugins/markdown_exporter.py b/jrnl/plugins/markdown_exporter.py index c3476d51..35ac3596 100644 --- a/jrnl/plugins/markdown_exporter.py +++ b/jrnl/plugins/markdown_exporter.py @@ -78,11 +78,11 @@ class MarkdownExporter(TextExporter): out = [] year, month = -1, -1 for e in journal.entries: - if not e.date.year == year: + if e.date.year != year: year = e.date.year out.append("# " + str(year)) out.append("") - if not e.date.month == month: + if e.date.month != month: month = e.date.month out.append("## " + e.date.strftime("%B")) out.append("")