Fix typing errors

This commit is contained in:
Veronica Berglyd Olsen
2025-03-30 23:17:25 +02:00
parent e8c4f2db25
commit 15de0c8dd7
8 changed files with 18 additions and 14 deletions
+2 -3
View File
@@ -537,12 +537,11 @@ def jsonEncode(data: dict | list | tuple, n: int = 0, nmax: int = 0) -> str:
# XML Helpers
##
def xmlIndent(tree: ET.Element | ET.ElementTree) -> None:
def xmlIndent(xml: ET.Element | ET.ElementTree) -> None:
"""A modified version of the XML indent function in the standard
library. It behaves more closely to how the one from lxml does.
"""
if isinstance(tree, ET.ElementTree):
tree = tree.getroot()
tree = xml.getroot() if isinstance(xml, ET.ElementTree) else xml
if not isinstance(tree, ET.Element):
return
+6 -3
View File
@@ -43,11 +43,13 @@ from novelwriter.error import logException
logger = logging.getLogger(__name__)
T_BuildValue = str | int | float | bool
# The Settings Template
# =====================
# Each entry contains a tuple on the form: (type, default)
SETTINGS_TEMPLATE: dict[str, tuple[type, str | int | float | bool]] = {
SETTINGS_TEMPLATE: dict[str, tuple[type, T_BuildValue]] = {
"filter.includeNovel": (bool, True),
"filter.includeNotes": (bool, False),
"filter.includeInactive": (bool, False),
@@ -378,7 +380,7 @@ class BuildSettings:
self._changed = True
return
def setValue(self, key: str, value: str | int | float | bool) -> None:
def setValue(self, key: str, value: T_BuildValue) -> None:
"""Set a specific value for a build setting."""
if (d := SETTINGS_TEMPLATE.get(key)) and len(d) == 2 and isinstance(value, d[0]):
self._changed = value != self._settings[key]
@@ -502,7 +504,8 @@ class BuildSettings:
self._settings = {k: v[1] for k, v in SETTINGS_TEMPLATE.items()}
if isinstance(settings, dict):
for key, value in settings.items():
self.setValue(RENAMED.get(key, key), value)
if isinstance(key, str) and isinstance(value, T_BuildValue):
self.setValue(RENAMED.get(key, key), value)
self._changed = False
+3 -3
View File
@@ -146,9 +146,9 @@ class GuiDocMerge(NDialog):
def _resetList(self) -> None:
"""Reset the content of the list box to its original state."""
logger.debug("Resetting list box content")
sHandle = self._data.get("sHandle", None)
itemList = self._data.get("origItems", [])
self._loadContent(sHandle, itemList)
if sHandle := self._data.get("sHandle"):
itemList = self._data.get("origItems", [])
self._loadContent(sHandle, itemList)
return
##
+2 -2
View File
@@ -192,8 +192,8 @@ class GuiDocSplit(NDialog):
@pyqtSlot()
def _reloadList(self) -> None:
"""Reload the content of the list box."""
sHandle = self._data.get("sHandle", None)
self._loadContent(sHandle)
if sHandle := self._data.get("sHandle"):
self._loadContent(sHandle)
return
##
+2 -2
View File
@@ -23,7 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from __future__ import annotations
from PyQt6.QtCore import QPropertyAnimation, Qt, pyqtProperty
from PyQt6.QtCore import QPropertyAnimation, Qt, pyqtProperty # pyright: ignore
from PyQt6.QtGui import QEnterEvent, QMouseEvent, QPainter, QPaintEvent, QResizeEvent
from PyQt6.QtWidgets import QAbstractButton, QWidget
@@ -60,7 +60,7 @@ class NSwitch(QAbstractButton):
def offset(self) -> int: # type: ignore
return self._offset
@offset.setter
@offset.setter # type: ignore
def offset(self, offset: int) -> None:
self._offset = offset
self.update()
+1
View File
@@ -1034,6 +1034,7 @@ class Tokenizer(ABC):
def _formatComment(self, style: ComStyle, key: str, text: str) -> tuple[str, T_Formats]:
"""Apply formatting to comments and notes."""
rFmt = []
tTxt, tFmt = self._extractFormats(text)
tFmt.insert(0, (0, TextFmt.COL_B, style.textClass))
tFmt.append((len(tTxt), TextFmt.COL_E, ""))
+1
View File
@@ -598,6 +598,7 @@ class ToOdt(Tokenizer):
def _textStyle(self, hFmt: int, fClass: str = "") -> str:
"""Return a text style for a given style code."""
tKey = str(hFmt)
color = None
if fClass and (color := self._classes.get(fClass)):
tKey = f"{tKey}:{fClass}"
if tKey in self._autoText:
+1 -1
View File
@@ -681,9 +681,9 @@ class _OutlineWidget(QWidget):
hFont.setBold(True)
hFont.setUnderline(True)
indent = False
if root := self.listView.invisibleRootItem():
parent = root
indent = False
for anchor, entry in data.items():
prefix, _, text = entry.partition("|")
if prefix in ("TT", "PT", "CH", "SC", "H1", "H2"):