[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: mypy complains that QAbstractItemModel.modelReset is a function, not a signal
From: Anton Yablokov <stsav012 () gmail ! com>
Date: 2021-05-16 9:58:03
Message-ID: CABrj0DM9YcuWa=sg0D-VoYRVW2OQPpUDwJA4SVyGqeYYVJMqww () mail ! gmail ! com
[Download RAW message or body]
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
🍏
[Attachment #3 (text/html)]
<div dir="ltr"><div>Dear developers,</div><div><br></div><div>I'm not sure \
whether it's right to address you about the issue but \
anyway.</div><div><br></div><div>I have the following class:</div><div><span \
style="font-family:monospace">class DataModel(QAbstractTableModel):<br> def \
__init__(self, parent: Optional[QObject]) -> None:<br> \
super().__init__(parent)<br> self._data: np.ndarray = np.empty((0, 0))<br> \
self._header: List[str] = []</span></div><br><div><span \
style="font-family:monospace"> def rowCount(self, parent: Optional[QModelIndex] \
= None, *, available_count: bool = False) -> int:<br> if \
available_count:<br> return self._data.shape[0]<br> \
return min(self._data.shape[0], self._rows_loaded)<br><br> def columnCount(self, \
parent: Optional[QModelIndex] = None) -> int:<br> return \
self._data.shape[1]<br><br> def data(self, index: QModelIndex, role: int = \
Qt.DisplayRole) -> Optional[str]:<br> if index.isValid() and role == \
Qt.DisplayRole:<br> return repr(self._data[row_index, \
column_index])</span></div><div><span style="font-family:monospace"> \
return None<br><br> def headerData(self, col: int, orientation: Qt.Orientation, \
role: int = Qt.DisplayRole) -> Optional[str]:<br> if orientation == \
Qt.Horizontal and role == Qt.DisplayRole and 0 <= col < len(self._header):<br> \
return self._header[col]<br> return None<br><br> def \
setHeaderData(self, section: int, orientation: Qt.Orientation, value: str, role: int \
= Qt.DisplayRole) -> bool:<br> if orientation == Qt.Horizontal and role \
== Qt.DisplayRole and 0 <= section < len(self._header):<br> \
self._header[section] = value<br> return True<br> return \
False</span></div><div><br></div><div>So, I create</div><div><span \
style="font-family:monospace">model = DataModel()</span></div><div>Then I connect its \
signal to a slot:</div><div><span \
style="font-family:monospace">model.modelReset.connect(lambda: \
print('modelReset'))</span><br><br></div><div>And that's where <span \
style="font-family:monospace">mypy</span> sees an error:</div><div><span \
style="font-family:monospace">error: "Callable[[], None]" has no attribute \
"connect"</span></div><div><br></div><div>Apparently, it's the matter \
of a stub, for the code works just fine.</div><div><br></div><div>It's merely an \
issue, for <span style="font-family:monospace">mypy</span> can be told to ignore \
it.</div><div><br></div><div>Thanks!</div><div><br></div><div>Best \
regards,</div><div>Anton<br></div><div><div><div dir="ltr" class="gmail_signature" \
data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div \
dir="ltr"><font size="6">🍏</font><br></div></div></div></div></div></div></div></div></div>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic