@@ -76,7 +76,7 @@ class NWIndex:
7676 a rebuild of the index data.
7777 """
7878
79- def __init__ (self , project : NWProject ):
79+ def __init__ (self , project : NWProject ) -> None :
8080
8181 self ._project = project
8282
@@ -91,30 +91,30 @@ def __init__(self, project: NWProject):
9191
9292 return
9393
94- def __repr__ (self ):
94+ def __repr__ (self ) -> str :
9595 return f"<NWIndex project='{ self ._project .data .name } '>"
9696
9797 ##
9898 # Properties
9999 ##
100100
101101 @property
102- def indexBroken (self ):
102+ def indexBroken (self ) -> bool :
103103 return self ._indexBroken
104104
105105 ##
106106 # Public Methods
107107 ##
108108
109- def clearIndex (self ):
109+ def clearIndex (self ) -> None :
110110 """Clear the index dictionaries and time stamps."""
111111 self ._tagsIndex .clear ()
112112 self ._itemIndex .clear ()
113113 self ._indexChange = 0.0
114114 self ._rootChange = {}
115115 return
116116
117- def rebuildIndex (self ):
117+ def rebuildIndex (self ) -> None :
118118 """Rebuild the entire index from scratch."""
119119 self .clearIndex ()
120120 for nwItem in self ._project .tree :
@@ -125,22 +125,20 @@ def rebuildIndex(self):
125125 self ._indexBroken = False
126126 return
127127
128- def deleteHandle (self , tHandle : str ):
128+ def deleteHandle (self , tHandle : str ) -> None :
129129 """Delete all entries of a given document handle."""
130130 logger .debug ("Removing item '%s' from the index" , tHandle )
131131 for tTag in self ._itemIndex .allItemTags (tHandle ):
132132 del self ._tagsIndex [tTag ]
133-
134133 del self ._itemIndex [tHandle ]
135-
136134 return
137135
138- def reIndexHandle (self , tHandle : str ) -> bool :
136+ def reIndexHandle (self , tHandle : str | None ) -> bool :
139137 """Put a file back into the index. This is used when files are
140138 moved from the archive or trash folders back into the active
141139 project.
142140 """
143- if not self ._project .tree .checkType (tHandle , nwItemType .FILE ):
141+ if tHandle is None or not self ._project .tree .checkType (tHandle , nwItemType .FILE ):
144142 return False
145143
146144 logger .debug ("Re-indexing item '%s'" , tHandle )
@@ -163,9 +161,8 @@ def rootChangedSince(self, rootHandle: str, checkTime: int | float) -> bool:
163161 # Load and Save Index to/from File
164162 ##
165163
166- def loadIndex (self ):
167- """Load index from last session from the project meta folder.
168- """
164+ def loadIndex (self ) -> bool :
165+ """Load index from last session from the project meta folder."""
169166 indexFile = self ._project .storage .getMetaFile (nwFiles .INDEX_FILE )
170167 if not isinstance (indexFile , Path ):
171168 return False
@@ -292,7 +289,7 @@ def scanText(self, tHandle: str, theText: str) -> bool:
292289 # Internal Indexer Helpers
293290 ##
294291
295- def _scanActive (self , tHandle : str , nwItem : NWItem , text : str , tags : dict ):
292+ def _scanActive (self , tHandle : str , nwItem : NWItem , text : str , tags : dict ) -> None :
296293 """Scan an active document for meta data."""
297294 nTitle = 0 # Line Number of the previous title
298295 cTitle = TT_NONE # Tag of the current title
@@ -355,7 +352,7 @@ def _scanActive(self, tHandle: str, nwItem: NWItem, text: str, tags: dict):
355352
356353 return
357354
358- def _scanInactive (self , nwItem : NWItem , text : str ):
355+ def _scanInactive (self , nwItem : NWItem , text : str ) -> None :
359356 """Scan an inactive document for meta data."""
360357 for aLine in text .splitlines ():
361358 if aLine .startswith ("#" ):
@@ -387,9 +384,8 @@ def _indexWordCounts(self, tHandle: str, text: str, sTitle: str):
387384 self ._itemIndex .setHeadingCounts (tHandle , sTitle , cC , wC , pC )
388385 return
389386
390- def _indexKeyword (
391- self , tHandle : str , line : str , sTitle : str , itemClass : nwItemClass , tags : dict
392- ):
387+ def _indexKeyword (self , tHandle : str , line : str , sTitle : str ,
388+ itemClass : nwItemClass , tags : dict ) -> None :
393389 """Validate and save the information about a reference to a tag
394390 in another file, or the setting of a tag in the file. A record
395391 of active tags is updated so that no longer used tags can be
0 commit comments