diff --git a/zxlive/rewrite_action.py b/zxlive/rewrite_action.py index 5cbc13e..ce0589a 100644 --- a/zxlive/rewrite_action.py +++ b/zxlive/rewrite_action.py @@ -2,7 +2,7 @@ import copy from dataclasses import dataclass, field -from typing import Callable, TYPE_CHECKING, Any, Optional, cast, Union +from typing import Callable, TYPE_CHECKING, Any, cast, Union import pyzx from PySide6.QtCore import Qt, QAbstractItemModel, QModelIndex, QPersistentModelIndex, Signal, QObject, QMetaObject @@ -176,16 +176,17 @@ def index(self, row: int, column: int, parent: Union[QModelIndex, QPersistentMod return self.createIndex(row, column, childItem) return QModelIndex() - def parent(self, index: QModelIndex | QPersistentModelIndex = QModelIndex()) -> QModelIndex: + def parent(self, index: QModelIndex | QPersistentModelIndex = QModelIndex()) -> QModelIndex: # type: ignore[override] if not index.isValid(): return QModelIndex() parent_item = cast(RewriteActionTree, index.internalPointer()).parent + row = parent_item is None or parent_item.row() - if parent_item == self.root_item: + if row is None or parent_item == self.root_item: return QModelIndex() - return self.createIndex(parent_item.row(), 0, parent_item) + return self.createIndex(row, 0, parent_item) def rowCount(self, parent: QModelIndex | QPersistentModelIndex = QModelIndex()) -> int: if parent.column() > 0: