mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-07-03 07:16:12 +02:00
Add type hints (#1614)
* Add type hints * Fix linters * Add remaining type hints * Fix type-checking linter * Update jrnl/DayOneJournal.py Co-authored-by: Jonathan Wren <jonathan@nowandwren.com>
This commit is contained in:
parent
c1eb0c54a3
commit
30b41fdb88
28 changed files with 219 additions and 120 deletions
|
@ -4,6 +4,7 @@
|
|||
import logging
|
||||
import os
|
||||
from textwrap import TextWrapper
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from jrnl.exception import JrnlException
|
||||
from jrnl.messages import Message
|
||||
|
@ -11,6 +12,10 @@ from jrnl.messages import MsgStyle
|
|||
from jrnl.messages import MsgText
|
||||
from jrnl.plugins.text_exporter import TextExporter
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from jrnl.Entry import Entry
|
||||
from jrnl.Journal import Journal
|
||||
|
||||
|
||||
class FancyExporter(TextExporter):
|
||||
"""This Exporter can convert entries and journals into text with unicode box drawing characters."""
|
||||
|
@ -35,7 +40,7 @@ class FancyExporter(TextExporter):
|
|||
border_m = "┘"
|
||||
|
||||
@classmethod
|
||||
def export_entry(cls, entry):
|
||||
def export_entry(cls, entry: "Entry") -> str:
|
||||
"""Returns a fancy unicode representation of a single entry."""
|
||||
date_str = entry.date.strftime(entry.journal.config["timeformat"])
|
||||
|
||||
|
@ -95,12 +100,12 @@ class FancyExporter(TextExporter):
|
|||
return "\n".join(card)
|
||||
|
||||
@classmethod
|
||||
def export_journal(cls, journal):
|
||||
def export_journal(cls, journal) -> str:
|
||||
"""Returns a unicode representation of an entire journal."""
|
||||
return "\n".join(cls.export_entry(entry) for entry in journal)
|
||||
|
||||
|
||||
def check_provided_linewrap_viability(linewrap, card, journal):
|
||||
def check_provided_linewrap_viability(linewrap: int, card: list[str], journal: "Journal"):
|
||||
if len(card[0]) > linewrap:
|
||||
width_violation = len(card[0]) - linewrap
|
||||
raise JrnlException(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue