66"""
77
88from __future__ import annotations
9- from typing import List , Tuple , Dict , Optional
109from dataclasses import dataclass
1110
1211from .snippets import Snippet
@@ -18,25 +17,25 @@ class Item(object):
1817 """Item of snippet cache."""
1918
2019 snippet : Snippet
21- tags : List [str ]
20+ tags : list [str ]
2221 excerpt : str
23- titlepath : List [str ]
24- keywords : List [str ]
22+ titlepath : list [str ]
23+ keywords : list [str ]
2524
2625
27- DocID = Tuple [str , str ] # (project, docname)
26+ DocID = tuple [str , str ] # (project, docname)
2827IndexID = str # UUID
29- Index = Tuple [str , str , List [str ], List [str ]] # (tags, excerpt, titlepath, keywords)
28+ Index = tuple [str , str , list [str ], list [str ]] # (tags, excerpt, titlepath, keywords)
3029
3130
3231class Cache (PDict ):
33- """A DocID -> List [Item] Cache."""
32+ """A DocID -> list [Item] Cache."""
3433
35- indexes : Dict [IndexID , Index ]
36- index_id_to_doc_id : Dict [IndexID , Tuple [DocID , int ]]
37- doc_id_to_index_ids : Dict [DocID , List [IndexID ]]
38- num_snippets_by_project : Dict [str , int ]
39- num_snippets_by_docid : Dict [DocID , int ]
34+ indexes : dict [IndexID , Index ]
35+ index_id_to_doc_id : dict [IndexID , tuple [DocID , int ]]
36+ doc_id_to_index_ids : dict [DocID , list [IndexID ]]
37+ num_snippets_by_project : dict [str , int ]
38+ num_snippets_by_docid : dict [DocID , int ]
4039
4140 def __init__ (self , dirname : str ) -> None :
4241 self .indexes = {}
@@ -46,7 +45,7 @@ def __init__(self, dirname: str) -> None:
4645 self .num_snippets_by_docid = {}
4746 super ().__init__ (dirname )
4847
49- def post_dump (self , key : DocID , items : List [Item ]) -> None :
48+ def post_dump (self , key : DocID , items : list [Item ]) -> None :
5049 """Overwrite PDict.post_dump."""
5150
5251 # Remove old indexes and index IDs if exists
@@ -74,7 +73,7 @@ def post_dump(self, key: DocID, items: List[Item]) -> None:
7473 self .num_snippets_by_docid [key ] = 0
7574 self .num_snippets_by_docid [key ] += len (items )
7675
77- def post_purge (self , key : DocID , items : List [Item ]) -> None :
76+ def post_purge (self , key : DocID , items : list [Item ]) -> None :
7877 """Overwrite PDict.post_purge."""
7978
8079 # Purge indexes
@@ -90,7 +89,7 @@ def post_purge(self, key: DocID, items: List[Item]) -> None:
9089 if self .num_snippets_by_docid [key ] == 0 :
9190 del self .num_snippets_by_docid [key ]
9291
93- def get_by_index_id (self , key : IndexID ) -> Optional [ Item ] :
92+ def get_by_index_id (self , key : IndexID ) -> Item | None :
9493 """Like get(), but use IndexID as key."""
9594 doc_id , item_index = self .index_id_to_doc_id .get (key , (None , None ))
9695 if not doc_id :
@@ -103,6 +102,6 @@ def gen_index_id(self) -> str:
103102
104103 return uuid .uuid4 ().hex [:7 ]
105104
106- def stringify (self , key : DocID , items : List [Item ]) -> str :
105+ def stringify (self , key : DocID , items : list [Item ]) -> str :
107106 """Overwrite PDict.stringify."""
108107 return key [1 ]
0 commit comments