Make some init parameters optional

This commit is contained in:
Tim Van Baak 2021-02-12 16:49:34 -08:00
parent 606537d959
commit 396f8d405a
2 changed files with 24 additions and 14 deletions

View File

@ -3,7 +3,7 @@ Logic for operations that depend on a whole collection of documents.
""" """
import os 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: 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]) docs = sorted(categories[category][topic], key=lambda x: x[0])
doc_links = map(document_link, docs) doc_links = map(document_link, docs)
value = '- ' + '<br>- '.join(doc_links) value = '- ' + '<br>- '.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) return Document(built_tabs)

View File

@ -4,7 +4,7 @@ Logic for reading and writing documents from files.
import argparse import argparse
from collections import OrderedDict from collections import OrderedDict
import json 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. 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.name: str = name
self.value: str = value self.value: str = value
self.options: TagOptions = options self.options: TagOptions = options if options is not None else TagOptions()
class DocumentTag: class DocumentTag:
@ -112,23 +117,28 @@ class DocumentTag:
self, self,
name: str, name: str,
value: str, value: str,
options: TagOptions, options: Optional[TagOptions] = None,
subtags: List[DocumentSubtag] subtags: Optional[List[DocumentSubtag]] = None
) -> None: ) -> None:
self.name: str = name self.name: str = name
self.value = value self.value: str = value
self.options = options self.options: TagOptions = options if options is not None else TagOptions()
self.subtags = subtags self.subtags: list = subtags if subtags is not None else []
class DocumentTab: class DocumentTab:
""" """
A division of tags within a document. A division of tags within a document.
""" """
def __init__(self, name: str, tags: List[DocumentTag], options: TabOptions) -> None: def __init__(
self.name = name self,
name: str,
tags: List[DocumentTag],
options: Optional[TabOptions] = None
) -> None:
self.name: str = name
self.tags: List[DocumentTag] = tags 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): def get_tag(self, name: str):
for tag in self.tags: for tag in self.tags: