From c87af823662f1169de067548f859989dad09fb2e Mon Sep 17 00:00:00 2001 From: outa Date: Tue, 11 Oct 2022 18:11:35 +0200 Subject: [PATCH] Fix linters --- jrnl/Entry.py | 13 +++++++++++-- jrnl/color.py | 7 +++++-- jrnl/config.py | 4 +++- jrnl/jrnl.py | 24 ++++++++++++++++++------ jrnl/output.py | 4 +++- jrnl/time.py | 8 ++++++-- 6 files changed, 46 insertions(+), 14 deletions(-) diff --git a/jrnl/Entry.py b/jrnl/Entry.py index 0d17ad47..9dfdf00f 100644 --- a/jrnl/Entry.py +++ b/jrnl/Entry.py @@ -5,16 +5,25 @@ import datetime import logging import os import re +from typing import TYPE_CHECKING import ansiwrap -from .Journal import Journal from .color import colorize from .color import highlight_tags_with_background_color +if TYPE_CHECKING: + from .Journal import Journal + class Entry: - def __init__(self, journal: Journal, date: datetime.datetime | None = None, text: str = "", starred: bool = False): + def __init__( + self, + journal: "Journal", + date: datetime.datetime | None = None, + text: str = "", + starred: bool = False, + ): self.journal = journal # Reference to journal mainly to access its config self.date = date or datetime.datetime.now() self.text = text diff --git a/jrnl/color.py b/jrnl/color.py index d92d113a..91d56254 100644 --- a/jrnl/color.py +++ b/jrnl/color.py @@ -4,12 +4,15 @@ import re from string import punctuation from string import whitespace +from typing import TYPE_CHECKING import colorama -from jrnl.Entry import Entry from jrnl.os_compat import on_windows +if TYPE_CHECKING: + from jrnl.Entry import Entry + if on_windows(): colorama.init() @@ -28,7 +31,7 @@ def colorize(string: str, color: str, bold: bool = False) -> str: def highlight_tags_with_background_color( - entry: Entry, text: str, color: str, is_title: bool = False + entry: "Entry", text: str, color: str, is_title: bool = False ) -> str: """ Takes a string and colorizes the tags in it based upon the config value for diff --git a/jrnl/config.py b/jrnl/config.py index e787d695..bcd67e2c 100644 --- a/jrnl/config.py +++ b/jrnl/config.py @@ -194,7 +194,9 @@ def is_config_json(config_path: str) -> bool: return config_file.strip().startswith("{") -def update_config(config: dict, new_config: dict, scope: str | None, force_local: bool = False) -> None: +def update_config( + config: dict, new_config: dict, scope: str | None, force_local: bool = False +) -> None: """Updates a config dict with new values - either global if scope is None or config['journals'][scope] is just a string pointing to a journal file, or within the scope""" diff --git a/jrnl/jrnl.py b/jrnl/jrnl.py index abf6c4c8..7f8fcc6e 100644 --- a/jrnl/jrnl.py +++ b/jrnl/jrnl.py @@ -1,8 +1,8 @@ # Copyright © 2012-2022 jrnl contributors # License: https://www.gnu.org/licenses/gpl-3.0.html -from argparse import Namespace import logging import sys +from argparse import Namespace from jrnl import install from jrnl import plugins @@ -15,8 +15,8 @@ from jrnl.editor import get_text_from_editor from jrnl.editor import get_text_from_stdin from jrnl.Entry import Entry from jrnl.exception import JrnlException -from jrnl.Journal import open_journal from jrnl.Journal import Journal +from jrnl.Journal import open_journal from jrnl.messages import Message from jrnl.messages import MsgStyle from jrnl.messages import MsgText @@ -322,7 +322,9 @@ def _other_entries(journal: Journal, entries: list[Entry]) -> list[Entry]: return [e for e in entries if e not in journal.entries] -def _edit_search_results(config: dict, journal: Journal, old_entries: list[Entry], **kwargs) -> None: +def _edit_search_results( + config: dict, journal: Journal, old_entries: list[Entry], **kwargs +) -> None: """ 1. Send the given journal entries to the user-configured editor 2. Print out stats on any modifications to journal @@ -356,7 +358,9 @@ def _edit_search_results(config: dict, journal: Journal, old_entries: list[Entry journal.write() -def _print_edited_summary(journal: Journal, old_stats: dict[str, int], **kwargs) -> None: +def _print_edited_summary( + journal: Journal, old_stats: dict[str, int], **kwargs +) -> None: stats = { "added": len(journal) - old_stats["count"], "deleted": old_stats["count"] - len(journal), @@ -399,7 +403,9 @@ def _get_predit_stats(journal: Journal) -> dict[str, int]: return {"count": len(journal)} -def _delete_search_results(journal: Journal, old_entries: list[Entry], **kwargs) -> None: +def _delete_search_results( + journal: Journal, old_entries: list[Entry], **kwargs +) -> None: entries_to_delete = journal.prompt_action_entries(MsgText.DeleteEntryQuestion) if entries_to_delete: @@ -409,7 +415,13 @@ def _delete_search_results(journal: Journal, old_entries: list[Entry], **kwargs) journal.write() -def _change_time_search_results(args: Namespace, journal: Journal, old_entries: list[Entry], no_prompt: bool = False, **kwargs) -> None: +def _change_time_search_results( + args: Namespace, + journal: Journal, + old_entries: list[Entry], + no_prompt: bool = False, + **kwargs +) -> None: # separate entries we are not editing other_entries = _other_entries(journal, old_entries) diff --git a/jrnl/output.py b/jrnl/output.py index bdf53dcd..0781263c 100644 --- a/jrnl/output.py +++ b/jrnl/output.py @@ -12,7 +12,9 @@ from jrnl.messages import MsgStyle from jrnl.messages import MsgText -def deprecated_cmd(old_cmd: str, new_cmd: str, callback: Callable | None = None, **kwargs) -> None: +def deprecated_cmd( + old_cmd: str, new_cmd: str, callback: Callable | None = None, **kwargs +) -> None: print_msg( Message( MsgText.DeprecatedCommand, diff --git a/jrnl/time.py b/jrnl/time.py index dbd2685d..ca1668b3 100644 --- a/jrnl/time.py +++ b/jrnl/time.py @@ -8,7 +8,7 @@ DEFAULT_FUTURE = datetime.datetime(FAKE_YEAR, 12, 31, 23, 59, 59) DEFAULT_PAST = datetime.datetime(FAKE_YEAR, 1, 1, 0, 0) -def __get_pdt_calendar() -> "pdt.Calendar": +def __get_pdt_calendar(): try: import parsedatetime.parsedatetime_consts as pdt except ImportError: @@ -22,7 +22,11 @@ def __get_pdt_calendar() -> "pdt.Calendar": def parse( - date_str: str | datetime.datetime, inclusive: bool = False, default_hour: int | None = None, default_minute: int | None = None, bracketed: bool = False + date_str: str | datetime.datetime, + inclusive: bool = False, + default_hour: int | None = None, + default_minute: int | None = None, + bracketed: bool = False, ) -> datetime.datetime | None: """Parses a string containing a fuzzy date and returns a datetime.datetime object""" if not date_str: