summaryrefslogtreecommitdiff
path: root/logical_search.py
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2022-02-09 10:30:44 -0800
committerScott Gasch <[email protected]>2022-02-09 10:30:44 -0800
commit244e8476c95d14a480be7160042b2b27b693ca63 (patch)
tree661f9903aac5ac05693d1f74a4272c4b42c41477 /logical_search.py
parentea7a67e2cf8dc6d7a41e7ff035acae7b36a41a1d (diff)
Ditch named tuples for dataclasses.
Diffstat (limited to 'logical_search.py')
-rw-r--r--logical_search.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/logical_search.py b/logical_search.py
index b55e689..41ed729 100644
--- a/logical_search.py
+++ b/logical_search.py
@@ -9,7 +9,8 @@ from __future__ import annotations
import enum
import sys
from collections import defaultdict
-from typing import Any, Dict, List, NamedTuple, Optional, Sequence, Set, Tuple, Union
+from dataclasses import dataclass, field
+from typing import Any, Dict, List, Optional, Sequence, Set, Tuple, Union
class ParseError(Exception):
@@ -20,13 +21,22 @@ class ParseError(Exception):
self.message = message
-class Document(NamedTuple):
- """A tuple representing a searchable document."""
+@dataclass
+class Document:
+ """A class representing a searchable document."""
- docid: str # a unique idenfier for the document
- tags: Set[str] # an optional set of tags
- properties: List[Tuple[str, str]] # an optional set of key->value properties
- reference: Any # an optional reference to something else
+ # A unique identifier for each document.
+ docid: str = ''
+
+ # A set of tag strings for this document. May be empty.
+ tags: Set[str] = field(default_factory=set)
+
+ # A list of key->value strings for this document. May be empty.
+ properties: List[Tuple[str, str]] = field(default_factory=list)
+
+ # An optional reference to something else; interpreted only by
+ # caller code, ignored here.
+ reference: Optional[Any] = None
class Operation(enum.Enum):