From 396f8d405a6dace129111bf79f6d86a134d28bd6 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Fri, 12 Feb 2021 16:49:34 -0800 Subject: [PATCH] Make some init parameters optional --- redstring/library.py | 6 +++--- redstring/parser.py | 32 +++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/redstring/library.py b/redstring/library.py index 0579b6c..097916c 100644 --- a/redstring/library.py +++ b/redstring/library.py @@ -3,7 +3,7 @@ Logic for operations that depend on a whole collection of documents. """ import os -from redstring.parser import load, TagOptions, DocumentTag, TabOptions, DocumentTab, Document +from redstring.parser import load, DocumentTag, DocumentTab, Document def generate_index_document(directory: str) -> Document: @@ -64,8 +64,8 @@ def generate_index_document(directory: str) -> Document: docs = sorted(categories[category][topic], key=lambda x: x[0]) doc_links = map(document_link, docs) value = '- ' + '
- '.join(doc_links) - built_tags.append(DocumentTag(topic, value, TagOptions(), [])) + built_tags.append(DocumentTag(topic, value)) - built_tabs.append(DocumentTab(category, built_tags, TabOptions())) + built_tabs.append(DocumentTab(category, built_tags)) return Document(built_tabs) diff --git a/redstring/parser.py b/redstring/parser.py index 7e23d92..7d005c5 100644 --- a/redstring/parser.py +++ b/redstring/parser.py @@ -4,7 +4,7 @@ Logic for reading and writing documents from files. import argparse from collections import OrderedDict import json -from typing import Any, List, IO +from typing import Any, List, IO, Optional # @@ -98,10 +98,15 @@ class DocumentSubtag: """ A keyvalue describing a document subject. """ - def __init__(self, name: str, value: str, options: TagOptions) -> None: + def __init__( + self, + name: str, + value: str, + options: Optional[TagOptions] = None + ) -> None: self.name: str = name self.value: str = value - self.options: TagOptions = options + self.options: TagOptions = options if options is not None else TagOptions() class DocumentTag: @@ -112,23 +117,28 @@ class DocumentTag: self, name: str, value: str, - options: TagOptions, - subtags: List[DocumentSubtag] + options: Optional[TagOptions] = None, + subtags: Optional[List[DocumentSubtag]] = None ) -> None: self.name: str = name - self.value = value - self.options = options - self.subtags = subtags + self.value: str = value + self.options: TagOptions = options if options is not None else TagOptions() + self.subtags: list = subtags if subtags is not None else [] class DocumentTab: """ A division of tags within a document. """ - def __init__(self, name: str, tags: List[DocumentTag], options: TabOptions) -> None: - self.name = name + def __init__( + self, + name: str, + tags: List[DocumentTag], + options: Optional[TabOptions] = None + ) -> None: + self.name: str = name self.tags: List[DocumentTag] = tags - self.options: TabOptions = options + self.options: TabOptions = options if options is not None else TabOptions() def get_tag(self, name: str): for tag in self.tags: