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:
outa 2022-11-05 23:29:50 +01:00 committed by GitHub
parent c1eb0c54a3
commit 30b41fdb88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 219 additions and 120 deletions

View file

@ -3,6 +3,7 @@
import os
import re
from typing import TYPE_CHECKING
from jrnl.exception import JrnlException
from jrnl.messages import Message
@ -11,6 +12,10 @@ from jrnl.messages import MsgText
from jrnl.output import print_msg
from jrnl.plugins.text_exporter import TextExporter
if TYPE_CHECKING:
from jrnl.Entry import Entry
from jrnl.Journal import Journal
class YAMLExporter(TextExporter):
"""This Exporter can convert entries and journals into Markdown formatted text with YAML front matter."""
@ -19,7 +24,7 @@ class YAMLExporter(TextExporter):
extension = "md"
@classmethod
def export_entry(cls, entry, to_multifile=True):
def export_entry(cls, entry: "Entry", to_multifile: bool = True) -> str:
"""Returns a markdown representation of a single entry, with YAML front matter."""
if to_multifile is False:
raise JrnlException(Message(MsgText.YamlMustBeDirectory, MsgStyle.ERROR))
@ -124,6 +129,6 @@ class YAMLExporter(TextExporter):
)
@classmethod
def export_journal(cls, journal):
def export_journal(cls, journal: "Journal"):
"""Returns an error, as YAML export requires a directory as a target."""
raise JrnlException(Message(MsgText.YamlMustBeDirectory, MsgStyle.ERROR))