mypy complains that QAbstractItemModel.modelReset is a function, not a signal
Anton Yablokov
stsav012 at gmail.com
Sun May 16 10:58:03 BST 2021
Dear developers,
I'm not sure whether it's right to address you about the issue but anyway.
I have the following class:
class DataModel(QAbstractTableModel):
def __init__(self, parent: Optional[QObject]) -> None:
super().__init__(parent)
self._data: np.ndarray = np.empty((0, 0))
self._header: List[str] = []
def rowCount(self, parent: Optional[QModelIndex] = None, *,
available_count: bool = False) -> int:
if available_count:
return self._data.shape[0]
return min(self._data.shape[0], self._rows_loaded)
def columnCount(self, parent: Optional[QModelIndex] = None) -> int:
return self._data.shape[1]
def data(self, index: QModelIndex, role: int = Qt.DisplayRole) ->
Optional[str]:
if index.isValid() and role == Qt.DisplayRole:
return repr(self._data[row_index, column_index])
return None
def headerData(self, col: int, orientation: Qt.Orientation, role: int =
Qt.DisplayRole) -> Optional[str]:
if orientation == Qt.Horizontal and role == Qt.DisplayRole and 0 <=
col < len(self._header):
return self._header[col]
return None
def setHeaderData(self, section: int, orientation: Qt.Orientation,
value: str, role: int = Qt.DisplayRole) -> bool:
if orientation == Qt.Horizontal and role == Qt.DisplayRole and 0 <=
section < len(self._header):
self._header[section] = value
return True
return False
So, I create
model = DataModel()
Then I connect its signal to a slot:
model.modelReset.connect(lambda: print('modelReset'))
And that's where mypy sees an error:
error: "Callable[[], None]" has no attribute "connect"
Apparently, it's the matter of a stub, for the code works just fine.
It's merely an issue, for mypy can be told to ignore it.
Thanks!
Best regards,
Anton
🍏
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20210516/b356f93c/attachment.htm>
More information about the PyQt
mailing list