From 7247d4dc7601e6a7fbb5e17fff55a7ae630f73e4 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Mon, 18 Mar 2024 18:37:21 +0100 Subject: [PATCH] Use correct type hint for generators --- novelwriter/core/index.py | 8 ++++---- novelwriter/core/project.py | 4 ++-- novelwriter/core/sessions.py | 4 ++-- novelwriter/core/status.py | 4 ++-- novelwriter/core/tree.py | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/novelwriter/core/index.py b/novelwriter/core/index.py index f91c31e5..66e2130b 100644 --- a/novelwriter/core/index.py +++ b/novelwriter/core/index.py @@ -33,7 +33,7 @@ import logging from time import time from typing import TYPE_CHECKING from pathlib import Path -from collections.abc import ItemsView, Iterable, Iterator +from collections.abc import Generator, ItemsView, Iterable from novelwriter import SHARED from novelwriter.enum import nwComment, nwItemClass, nwItemType, nwItemLayout @@ -523,7 +523,7 @@ class NWIndex: return tItem[sTitle] return None - def iterItemHeadings(self, tHandle: str) -> Iterator[str, IndexHeading]: + def iterItemHeadings(self, tHandle: str) -> Generator[str, IndexHeading]: """Get all headings for a specific item.""" if tItem := self._itemIndex[tHandle]: yield from tItem.items() @@ -531,7 +531,7 @@ class NWIndex: def novelStructure( self, rootHandle: str | None = None, activeOnly: bool = True - ) -> Iterator[tuple[str, str, str, IndexHeading]]: + ) -> Generator[tuple[str, str, str, IndexHeading]]: """Iterate over all titles in the novel, in the correct order as they appear in the tree view and in the respective document files, but skipping all note files. @@ -673,7 +673,7 @@ class NWIndex: def getTagsData( self, activeOnly: bool = True - ) -> Iterator[tuple[str, str, str, IndexItem | None, IndexHeading | None]]: + ) -> Generator[tuple[str, str, str, IndexItem | None, IndexHeading | None]]: """Return all known tags.""" for tag, data in self._tagsIndex.items(): iItem = self._itemIndex[data.get("handle")] diff --git a/novelwriter/core/project.py b/novelwriter/core/project.py index 14d4bd29..b69c29bc 100644 --- a/novelwriter/core/project.py +++ b/novelwriter/core/project.py @@ -31,7 +31,7 @@ from time import time from typing import TYPE_CHECKING from pathlib import Path from functools import partial -from collections.abc import Iterator +from collections.abc import Generator from PyQt5.QtCore import QCoreApplication @@ -517,7 +517,7 @@ class NWProject: # Class Methods ## - def iterProjectItems(self) -> Iterator[NWItem]: + def iterProjectItems(self) -> Generator[NWItem]: """This function ensures that the item tree loaded is sent to the GUI tree view in such a way that the tree can be built. That is, the parent item must be sent before its child. In principle, diff --git a/novelwriter/core/sessions.py b/novelwriter/core/sessions.py index 62e88960..5356c6d4 100644 --- a/novelwriter/core/sessions.py +++ b/novelwriter/core/sessions.py @@ -29,7 +29,7 @@ import logging from time import time from typing import TYPE_CHECKING from pathlib import Path -from collections.abc import Iterator +from collections.abc import Generator from novelwriter.error import logException from novelwriter.common import formatTimeStamp @@ -110,7 +110,7 @@ class NWSessionLog: return True - def iterRecords(self) -> Iterator[dict]: + def iterRecords(self) -> Generator[dict]: """Iterate through all records in the log.""" sessFile = self._project.storage.getMetaFile(nwFiles.SESS_FILE) if isinstance(sessFile, Path) and sessFile.is_file(): diff --git a/novelwriter/core/status.py b/novelwriter/core/status.py index 71a48747..ad8db0df 100644 --- a/novelwriter/core/status.py +++ b/novelwriter/core/status.py @@ -28,7 +28,7 @@ import random import logging from typing import TYPE_CHECKING, Literal -from collections.abc import ItemsView, Iterator, KeysView, ValuesView +from collections.abc import Generator, ItemsView, Iterator, KeysView, ValuesView from PyQt5.QtGui import QIcon, QPainter, QPainterPath, QPixmap, QColor from PyQt5.QtCore import QRectF, Qt @@ -193,7 +193,7 @@ class NWStatus: self._store[key]["count"] += 1 return - def pack(self) -> Iterator[tuple[str, dict]]: + def pack(self) -> Generator[tuple[str, dict]]: """Pack the status entries into a dictionary.""" for key, data in self._store.items(): yield (data["name"], { diff --git a/novelwriter/core/tree.py b/novelwriter/core/tree.py index 3e0a1b00..4dea1a95 100644 --- a/novelwriter/core/tree.py +++ b/novelwriter/core/tree.py @@ -28,7 +28,7 @@ import logging from typing import TYPE_CHECKING, Literal, overload from pathlib import Path -from collections.abc import Iterator +from collections.abc import Generator, Iterator from novelwriter.enum import nwItemClass, nwItemLayout, nwItemType from novelwriter.error import logException @@ -387,7 +387,7 @@ class NWTree: rootClasses.add(nwItem.itemClass) return rootClasses - def iterRoots(self, itemClass: nwItemClass | None) -> Iterator[tuple[str, NWItem]]: + def iterRoots(self, itemClass: nwItemClass | None) -> Generator[tuple[str, NWItem]]: """Iterate over all root items of a given class in order.""" for tHandle in self._order: nwItem = self.__getitem__(tHandle)