Use Ruff for linting and fix a ton of issues
This commit is contained in:
@@ -294,12 +294,12 @@ class BuildSettings:
|
||||
def getInt(self, key: str) -> int:
|
||||
"""Type safe value access for integers."""
|
||||
value = self._settings.get(key, SETTINGS_TEMPLATE.get(key, (None, None))[1])
|
||||
return int(value) if isinstance(value, (int, float)) else 0
|
||||
return int(value) if isinstance(value, int | float) else 0
|
||||
|
||||
def getFloat(self, key: str) -> float:
|
||||
"""Type safe value access for floats."""
|
||||
value = self._settings.get(key, SETTINGS_TEMPLATE.get(key, (None, None))[1])
|
||||
return float(value) if isinstance(value, (int, float)) else 0.0
|
||||
return float(value) if isinstance(value, int | float) else 0.0
|
||||
|
||||
##
|
||||
# Setters
|
||||
|
||||
@@ -379,7 +379,7 @@ class ProjectBuilder:
|
||||
"""Build or copy a project from a data dictionary."""
|
||||
if isinstance(data, dict):
|
||||
path = data.get("path", None) or None
|
||||
if isinstance(path, (str, Path)):
|
||||
if isinstance(path, str | Path):
|
||||
self._path = Path(path).resolve()
|
||||
if data.get("sample", False):
|
||||
return self._extractSampleProject(self._path)
|
||||
@@ -509,7 +509,7 @@ class ProjectBuilder:
|
||||
|
||||
# Also add the archive and trash folders
|
||||
project.newRoot(nwItemClass.ARCHIVE)
|
||||
project.tree.trash # Triggers the creation of Trash
|
||||
_ = project.tree.trash # Triggers the creation of Trash
|
||||
|
||||
project.saveProject()
|
||||
project.closeProject()
|
||||
|
||||
@@ -316,13 +316,13 @@ class NWBuildDocument:
|
||||
bldObj.setStyles(self._build.getBool("html.addStyles"))
|
||||
bldObj.setReplaceUnicode(self._build.getBool("format.stripUnicode"))
|
||||
|
||||
if isinstance(bldObj, (ToOdt, ToDocX)):
|
||||
if isinstance(bldObj, ToOdt | ToDocX):
|
||||
bldObj.setHeaderFormat(
|
||||
self._build.getStr("doc.pageHeader"),
|
||||
self._build.getInt("doc.pageCountOffset"),
|
||||
)
|
||||
|
||||
if isinstance(bldObj, (ToOdt, ToDocX, ToQTextDocument)):
|
||||
if isinstance(bldObj, ToOdt | ToDocX | ToQTextDocument):
|
||||
scale = nwLabels.UNIT_SCALE.get(self._build.getStr("format.pageUnit"), 1.0)
|
||||
pW, pH = nwLabels.PAPER_SIZE.get(self._build.getStr("format.pageSize"), (-1.0, -1.0))
|
||||
bldObj.setPageLayout(
|
||||
|
||||
@@ -333,8 +333,9 @@ class ProjectModel(QAbstractItemModel):
|
||||
return self.createIndex(parent.row(), 0, parent)
|
||||
return QModelIndex()
|
||||
|
||||
def index(self, row: int, column: int, parent: QModelIndex = QModelIndex()) -> QModelIndex:
|
||||
def index(self, row: int, column: int, parent: QModelIndex | None = None) -> QModelIndex:
|
||||
"""Get the index of a child item of a parent."""
|
||||
parent = parent or QModelIndex()
|
||||
if self.hasIndex(row, column, parent):
|
||||
node: ProjectNode = parent.internalPointer() if parent.isValid() else self._root
|
||||
if child := node.child(row):
|
||||
|
||||
Reference in New Issue
Block a user