-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
Consider the following code example:
import sys
from PySide2 import QtCore, QtGui, QtWidgets
class Window(QtWidgets.QWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._label = QtWidgets.QLabel("Try Delete", self)
self._shortcut = QtWidgets.QShortcut(QtGui.QKeySequence.StandardKey.Delete, self)
self._shortcut.activated.connect(self.on_delete)
self._layout = QtWidgets.QHBoxLayout()
self._layout.addWidget(self._label)
self.setLayout(self._layout)
self.resize(150, 100)
self.show()
@QtCore.Slot()
def on_delete(self):
print("Deleting!")
app = QtWidgets.QApplication(sys.argv)
win = Window()
win.show()
sys.exit(app.exec_())This code successfully runs with PySide2, and opens a window where if you press "Delete" then a message is output to the terminal.
mypy raises errors with this code, however:
file.py:9: error: No overload variant of "QShortcut" matches argument types "StandardKey", "Window" [call-overload]
file.py:9: note: Possible overload variants:
file.py:9: note: def __init__(self, key: QKeySequence | str, parent: QWidget | None, member: bytes | None = ..., ambiguousMember: bytes | None = ..., shortcutContext: ShortcutContext = ..., destroyed: Callable[..., Any] = ..., objectName: str = ..., objectNameChanged: Callable[..., Any] = ...) -> QShortcut
file.py:9: note: def __init__(self, arg__1: QKeySequence | str, arg__2: QWidget, arg__3: Callable[..., Any], arg__4: ShortcutContext = ..., destroyed: Callable[..., Any] = ..., objectName: str = ..., objectNameChanged: Callable[..., Any] = ...) -> QShortcut
file.py:9: note: def __init__(self, parent: QWidget | None, destroyed: Callable[..., Any] = ..., objectName: str = ..., objectNameChanged: Callable[..., Any] = ...) -> QShortcut
Found 1 error in 1 file (checked 1 source file)
PySide2 incorrectly typed the places where is accepts a QKeySequence as QKeySequence | str, when it actually accepts Union[PySide6.QtGui.QKeySequence, PySide6.QtCore.QKeyCombination, PySide6.QtGui.QKeySequence.StandardKey, str, int]. This was corrected in PySide6.
I believe that types-PySide2 can also be updated to accept Union[QKeySequence, QKeySequence.StandardKey, str, int] where QKeySequence | str is currently accepted.
Metadata
Metadata
Assignees
Labels
No labels