Update linting for main code

This commit is contained in:
Veronica Berglyd Olsen
2025-08-27 21:00:09 +02:00
parent 84ff1f4640
commit c174f8f931
80 changed files with 461 additions and 1653 deletions
+6 -42
View File
@@ -22,7 +22,7 @@ General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
""" # noqa
from __future__ import annotations
import json
@@ -56,7 +56,7 @@ KEY_SOURCE = "0123456789bcdfghjklmnpqrstvwxz"
class Index:
"""Core: Project Index
"""Core: Project Index.
This class holds the entire index for a given project. The index
contains the data that isn't stored in the project items themselves.
@@ -99,8 +99,6 @@ class Index:
self._indexChange = 0.0
self._rootChange = {}
return
def __repr__(self) -> str:
return f"<Index project='{self._project.data.name}'>"
@@ -129,7 +127,6 @@ class Index:
def setNovelModelExtraColumn(self, extra: nwNovelExtra) -> None:
"""Set the data content type of the novel model extra column."""
self._novelExtra = extra
return
##
# Public Methods
@@ -142,7 +139,6 @@ class Index:
self._indexChange = 0.0
self._rootChange = {}
SHARED.emitIndexCleared(self._project)
return
def rebuild(self) -> None:
"""Rebuild the entire index from scratch."""
@@ -158,7 +154,6 @@ class Index:
for tHandle in self._novelModels:
self.refreshNovelModel(tHandle)
SHARED.clearMainProgress()
return
def deleteHandle(self, tHandle: str) -> None:
"""Delete all entries of a given document handle."""
@@ -168,7 +163,6 @@ class Index:
del self._tagsIndex[tTag]
del self._itemIndex[tHandle]
SHARED.emitIndexChangedTags(self._project, [], delTags)
return
def reIndexHandle(self, tHandle: str | None) -> None:
"""Put a file back into the index. This is used when files are
@@ -178,7 +172,6 @@ class Index:
if tHandle and self._project.tree.checkType(tHandle, nwItemType.FILE):
logger.debug("Re-indexing item '%s'", tHandle)
self.scanText(tHandle, self._project.storage.getDocumentText(tHandle))
return
def refreshHandle(self, tHandle: str) -> None:
"""Update the class for all tags of a handle."""
@@ -188,7 +181,6 @@ class Index:
self.deleteHandle(tHandle)
else:
self._tagsIndex.updateClass(tHandle, item.itemClass.name)
return
def indexChangedSince(self, checkTime: int | float) -> bool:
"""Check if the index has changed since a given time."""
@@ -211,7 +203,6 @@ class Index:
model.setExtraColumn(self._novelExtra)
self._appendSubTreeToModel(tHandle, model)
model.endResetModel()
return
def updateNovelModelData(self, nwItem: NWItem) -> bool:
"""Refresh a novel model."""
@@ -428,8 +419,6 @@ class Index:
if updated or deleted:
SHARED.emitIndexChangedTags(self._project, updated, deleted)
return
def _scanInactive(self, nwItem: NWItem, text: str) -> None:
"""Scan an inactive document for meta data."""
for line in text.splitlines():
@@ -438,7 +427,6 @@ class Index:
if hDepth != "H0":
nwItem.setMainHeading(hDepth)
break
return
def _splitHeading(self, line: str) -> tuple[str, str]:
"""Split a heading into its heading level and text value."""
@@ -462,7 +450,6 @@ class Index:
"""Count text stats and save the counts to the index."""
cC, wC, pC = standardCounter(text)
self._itemIndex.setHeadingCounts(tHandle, sTitle, cC, wC, pC)
return
def _indexKeyword(
self, tHandle: str, line: str, sTitle: str, itemClass: nwItemClass, tags: dict[str, bool]
@@ -498,7 +485,6 @@ class Index:
model.setExtraColumn(self._novelExtra)
self._appendSubTreeToModel(tHandle, model)
self._novelModels[tHandle] = model
return
def _appendSubTreeToModel(self, tHandle: str, model: NovelModel) -> None:
"""Append all active novel documents to a novel model."""
@@ -509,7 +495,6 @@ class Index:
and node.item.isActive
):
model.append(node)
return
##
# Check @ Lines
@@ -683,15 +668,13 @@ class Index:
"words": hItem.wordCount,
}
result = [(
return [(
tKey,
tData[tKey]["level"],
tData[tKey]["title"],
tData[tKey]["words"]
) for tKey in tOrder]
return result
def getCounts(self, tHandle: str, sTitle: str | None = None) -> tuple[int, int, int]:
"""Return the counts for a file, or a section of a file,
starting at title sTitle if it is provided.
@@ -796,7 +779,7 @@ class Index:
# =====================
class TagsIndex:
"""Core: Tags Index Wrapper Class
"""Core: Tags Index Wrapper Class.
A wrapper class that holds the reverse lookup tags index. This is
just a simple wrapper around a single dictionary to keep tighter
@@ -807,14 +790,12 @@ class TagsIndex:
def __init__(self) -> None:
self._tags: dict[str, dict[str, str]] = {}
return
def __contains__(self, tagKey: str) -> bool:
return tagKey.lower() in self._tags
def __delitem__(self, tagKey: str) -> None:
self._tags.pop(tagKey.lower(), None)
return
def __getitem__(self, tagKey: str) -> dict | None:
return self._tags.get(tagKey.lower(), None)
@@ -826,7 +807,6 @@ class TagsIndex:
def clear(self) -> None:
"""Clear the index."""
self._tags = {}
return
def items(self) -> ItemsView:
"""Return a dictionary view of all tags."""
@@ -842,7 +822,6 @@ class TagsIndex:
"heading": sTitle,
"class": className,
}
return
def tagName(self, tagKey: str, default: str = "") -> str:
"""Get the name of a given tag."""
@@ -882,7 +861,6 @@ class TagsIndex:
for entry in self._tags.values():
if entry.get("handle") == tHandle:
entry["class"] = className
return
##
# Pack/Unpack
@@ -925,11 +903,9 @@ class TagsIndex:
self.add(name, display, handle, heading, className)
return
class IndexCache:
"""Core: Item Index Lookup Data Class
"""Core: Item Index Lookup Data Class.
A small data class passed between all objects of the Item Index
which provides lookup capabilities and caching for shared data.
@@ -941,14 +917,13 @@ class IndexCache:
self.tags: TagsIndex = tagsIndex
self.story: set[str] = set()
self.note: set[str] = set()
return
# The Item Index Objects
# ======================
class ItemIndex:
"""Core: Item Index Wrapper Class
"""Core: Item Index Wrapper Class.
A wrapper object holding the indexed items. This is a wrapper
class around a single storage dictionary with a set of utility
@@ -963,14 +938,12 @@ class ItemIndex:
self._project = project
self._cache = IndexCache(tagsIndex)
self._items: dict[str, IndexNode] = {}
return
def __contains__(self, tHandle: str) -> bool:
return tHandle in self._items
def __delitem__(self, tHandle: str) -> None:
self._items.pop(tHandle, None)
return
def __getitem__(self, tHandle: str) -> IndexNode | None:
return self._items.get(tHandle, None)
@@ -982,14 +955,12 @@ class ItemIndex:
def clear(self) -> None:
"""Clear the index."""
self._items = {}
return
def add(self, tHandle: str, nwItem: NWItem) -> None:
"""Add a new item to the index. This will overwrite the item if
it already exists.
"""
self._items[tHandle] = IndexNode(self._cache, tHandle, nwItem)
return
def allStoryKeys(self) -> set[str]:
"""Return all story structure keys."""
@@ -1064,7 +1035,6 @@ class ItemIndex:
"""
if tHandle in self._items:
self._items[tHandle].setHeadingCounts(sTitle, cC, wC, pC)
return
def setHeadingComment(
self, tHandle: str, sTitle: str,
@@ -1073,25 +1043,21 @@ class ItemIndex:
"""Set a story comment for a heading on a given item."""
if tHandle in self._items:
self._items[tHandle].setHeadingComment(sTitle, comment, key, text)
return
def setHeadingTag(self, tHandle: str, sTitle: str, tagKey: str) -> None:
"""Set the main tag for a heading on a given item."""
if tHandle in self._items:
self._items[tHandle].setHeadingTag(sTitle, tagKey)
return
def addHeadingRef(self, tHandle: str, sTitle: str, tagKeys: list[str], refType: str) -> None:
"""Set the reference tags for a heading on a given item."""
if tHandle in self._items:
self._items[tHandle].addHeadingRef(sTitle, tagKeys, refType)
return
def addNoteKey(self, tHandle: str, style: T_NoteTypes, key: str) -> None:
"""Set notes key for a given item."""
if tHandle in self._items:
self._items[tHandle].addNoteKey(style, key)
return
def genNewNoteKey(self, tHandle: str, style: T_NoteTypes) -> str:
"""Set notes key for a given item."""
@@ -1131,5 +1097,3 @@ class ItemIndex:
tItem = IndexNode(self._cache, tHandle, nwItem)
tItem.unpackData(tData)
self._items[tHandle] = tItem
return