Use correct type hint for generators
This commit is contained in:
@@ -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")]
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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"], {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user