More cleanup, yey!
[python_utils.git] / logical_search.py
index c324ff850895bb94ee29d84448c4449ad5fe1727..b55e68901501ad2e68a7f45df034866072c3f61b 100644 (file)
@@ -1,27 +1,22 @@
 #!/usr/bin/env python3
 
+"""This is a module concerned with the creation of and searching of a
+corpus of documents.  The corpus is held in memory for fast
+searching."""
+
 from __future__ import annotations
 
-from collections import defaultdict
 import enum
 import sys
-from typing import (
-    Any,
-    Dict,
-    List,
-    NamedTuple,
-    Optional,
-    Set,
-    Sequence,
-    Tuple,
-    Union,
-)
+from collections import defaultdict
+from typing import Any, Dict, List, NamedTuple, Optional, Sequence, Set, Tuple, Union
 
 
 class ParseError(Exception):
     """An error encountered while parsing a logical search expression."""
 
     def __init__(self, message: str):
+        super().__init__()
         self.message = message
 
 
@@ -178,9 +173,7 @@ class Corpus(object):
     def invert_docid_set(self, original: Set[str]) -> Set[str]:
         """Invert a set of docids."""
 
-        return set(
-            [docid for docid in self.documents_by_docid.keys() if docid not in original]
-        )
+        return set([docid for docid in self.documents_by_docid.keys() if docid not in original])
 
     def get_doc(self, docid: str) -> Optional[Document]:
         """Given a docid, retrieve the previously added Document."""
@@ -260,9 +253,7 @@ class Corpus(object):
                     operation = Operation.from_token(token)
                     operand_count = operation.num_operands()
                     if len(node_stack) < operand_count:
-                        raise ParseError(
-                            f"Incorrect number of operations for {operation}"
-                        )
+                        raise ParseError(f"Incorrect number of operations for {operation}")
                     for _ in range(operation.num_operands()):
                         args.append(node_stack.pop())
                     node = Node(corpus, operation, args)
@@ -352,9 +343,7 @@ class Node(object):
                         try:
                             key, value = tag.split(":")
                         except ValueError as v:
-                            raise ParseError(
-                                f'Invalid key:value syntax at "{tag}"'
-                            ) from v
+                            raise ParseError(f'Invalid key:value syntax at "{tag}"') from v
                         if value == "*":
                             r = self.corpus.get_docids_with_property(key)
                         else: