Skip to content

fix: Add kwargs to add_action wrapper#531

Open
beatreichenbach wants to merge 1 commit intospyder-ide:masterfrom
beatreichenbach:add_action-kwargs
Open

fix: Add kwargs to add_action wrapper#531
beatreichenbach wants to merge 1 commit intospyder-ide:masterfrom
beatreichenbach:add_action-kwargs

Conversation

@beatreichenbach
Copy link
Contributor

This adds the kwargs back to the add_action function and should hopefully fix #472.

However, before proceeding, I would like to add tests for all cases. I'm a bit unsure what cases should be supported. Does this cover everything?

# Case 1 (arg__2 is a callable and arg__3 is kwarg 'shortcut')
arg__1: str
arg__2: object
arg__3: QKeySequence = 0

# Case 2 (arg__3 is a callable and arg__4 is kwarg 'shortcut')
arg__1: QIcon
arg__2: str
arg__3: object
arg__4: QKeySequence = 0 

# Case 3
text: str

# Case 4
icon: QIcon
text: str

# Case 5 (shortcut can be arg or kwarg)
text: str
receiver: QObject
member: str
shortcut: QKeySequence = 0

# Case 6 (shortcut can be arg or kwarg)
icon: QIcon
text: str
receiver: QObject
member: str
shortcut: QKeySequence = 0

# Case 7 (PySide6>=6.3, PyQt6>=6.3)
text: str
shortcut: QKeySequence

# Case 8 (PySide6>=6.3, PyQt6>=6.3)
icon: QIcon
text: str
shortcut: QKeySequence

# Case 9 (PySide6>=6.3, PyQt6>=6.3)
text: str
shortcut: QKeySequence
receiver: QObject
member: str
type: ConnectionType = ConnectionType.AutoConnection

# Case 10 (PySide6>=6.3, PyQt6>=6.3)
icon: QIcon
text: str
shortcut: QKeySequence
receiver: QObject
member: str
type: ConnectionType = ConnectionType.AutoConnection

@coveralls
Copy link

Coverage Status

coverage: 90.757% (+0.9%) from 89.834%
when pulling 8920bed on beatreichenbach:add_action-kwargs
into cc853c3 on spyder-ide:master.

@ccordoba12 ccordoba12 requested a review from dalthviz February 15, 2026 19:42
@dalthviz
Copy link
Member

Hi @beatreichenbach thank you for giving that issue a check! The summary of possible signatures that you mention makes sense to me 👍 For completness, checking to the different bindings and got the following signatures when checking help(QMenu.addAction) from an interpreter:

  • PyQt5:
addAction(...)
    addAction(self, action: Optional[QAction])
    addAction(self, text: Optional[str]) -> Optional[QAction]
    addAction(self, icon: QIcon, text: Optional[str]) -> Optional[QAction]
    addAction(self, text: Optional[str], slot: PYQT_SLOT, shortcut: Union[QKeySequence, QKeySequence.StandardKey, Optional[str], int] = 0) -> Optional[QAction]
    addAction(self, icon: QIcon, text: Optional[str], slot: PYQT_SLOT, shortcut: Union[QKeySequence, QKeySequence.StandardKey, Optional[str], int] = 0) -> Optional[QAction]
  • PySide2:
addAction(...)
    addAction(self, arg__1: PySide2.QtGui.QIcon, arg__2: str, arg__3: object, arg__4: typing.Optional[PySide2.QtGui.QKeySequence] = None) -> None
    addAction(self, arg__1: PySide2.QtWidgets.QAction) -> None
    addAction(self, arg__1: str, arg__2: object, arg__3: typing.Optional[PySide2.QtGui.QKeySequence] = None) -> None
    addAction(self, icon: PySide2.QtGui.QIcon, text: str) -> PySide2.QtWidgets.QAction
    addAction(self, icon: PySide2.QtGui.QIcon, text: str, receiver: PySide2.QtCore.QObject, member: bytes, shortcut: typing.Optional[PySide2.QtGui.QKeySequence] = None) -> PySide2.QtWidgets.QAction
    addAction(self, text: str) -> PySide2.QtWidgets.QAction
    addAction(self, text: str, receiver: PySide2.QtCore.QObject, member: bytes, shortcut: typing.Optional[PySide2.QtGui.QKeySequence] = None) -> PySide2.QtWidgets.QAction
  • PyQt6:
addAction(...) method of PyQt6.sip.wrappertype instance
    addAction(self, icon: QIcon, text: Optional[str]) -> Optional[QAction]
    addAction(self, icon: QIcon, text: Optional[str], slot: PYQT_SLOT, type: Qt.ConnectionType = Qt.AutoConnection) -> Optional[QAction]
    addAction(self, icon: QIcon, text: Optional[str], shortcut: Union[QKeySequence, QKeySequence.StandardKey, Optional[str], int]) -> Optional[QAction]
    addAction(self, icon: QIcon, text: Optional[str], shortcut: Union[QKeySequence, QKeySequence.StandardKey, Optional[str], int], slot: PYQT_SLOT, type: Qt.ConnectionType = Qt.AutoConnection) -> Optional[QAction]
    addAction(self, text: Optional[str]) -> Optional[QAction]
    addAction(self, text: Optional[str], shortcut: Union[QKeySequence, QKeySequence.StandardKey, Optional[str], int]) -> Optional[QAction]
    addAction(self, text: Optional[str], slot: PYQT_SLOT, type: Qt.ConnectionType = Qt.AutoConnection) -> Optional[QAction]
    addAction(self, text: Optional[str], shortcut: Union[QKeySequence, QKeySequence.StandardKey, Optional[str], int], slot: PYQT_SLOT, type: Qt.ConnectionType = Qt.AutoConnection) -> Optional[QAction]
    addAction(self, action: Optional[QAction])
  • PySide6
addAction(...)
    addAction(self, action: PySide6.QtGui.QAction, /) -> None
    addAction(self, text: str, /) -> PySide6.QtGui.QAction
    addAction(self, text: str, receiver: PySide6.QtCore.QObject, member: Union[bytes, bytearray, memoryview], /, type: PySide6.QtCore.Qt.ConnectionType = Instance(Qt.AutoConnection)) -> PySide6.QtGui.QAction
    addAction(self, text: str, receiver: PySide6.QtCore.QObject, member: Union[bytes, bytearray, memoryview], shortcut: Union[PySide6.QtGui.QKeySequence, PySide6.QtCore.QKeyCombination, PySide6.QtGui.QKeySequence.StandardKey, str, int], /) -> PySide6.QtGui.QAction
    addAction(self, text: str, shortcut: Union[PySide6.QtGui.QKeySequence, PySide6.QtCore.QKeyCombination, PySide6.QtGui.QKeySequence.StandardKey, str, int], /) -> PySide6.QtGui.QAction
    addAction(self, text: str, shortcut: Union[PySide6.QtGui.QKeySequence, PySide6.QtCore.QKeyCombination, PySide6.QtGui.QKeySequence.StandardKey, str, int], receiver: PySide6.QtCore.QObject, member: Union[bytes, bytearray, memoryview], /, type: PySide6.QtCore.Qt.ConnectionType = Instance(Qt.AutoConnection)) -> PySide6.QtGui.QAction
    addAction(self, text: str, shortcut: Union[PySide6.QtGui.QKeySequence, PySide6.QtCore.QKeyCombination, PySide6.QtGui.QKeySequence.StandardKey, str, int], callable: object, /) -> PySide6.QtGui.QAction
    addAction(self, text: str, callable: object, /) -> PySide6.QtGui.QAction
    addAction(self, text: str, arg__2: object, /, shortcut: Union[PySide6.QtGui.QKeySequence, PySide6.QtCore.QKeyCombination, PySide6.QtGui.QKeySequence.StandardKey, str, int, NoneType] = None) -> None
    addAction(self, icon: Union[PySide6.QtGui.QIcon, PySide6.QtGui.QPixmap], text: str, /) -> PySide6.QtGui.QAction
    addAction(self, icon: Union[PySide6.QtGui.QIcon, PySide6.QtGui.QPixmap], text: str, receiver: PySide6.QtCore.QObject, member: Union[bytes, bytearray, memoryview], /, type: PySide6.QtCore.Qt.ConnectionType = Instance(Qt.AutoConnection)) -> PySide6.QtGui.QAction
    addAction(self, icon: Union[PySide6.QtGui.QIcon, PySide6.QtGui.QPixmap], text: str, receiver: PySide6.QtCore.QObject, member: Union[bytes, bytearray, memoryview], shortcut: Union[PySide6.QtGui.QKeySequence, PySide6.QtCore.QKeyCombination, PySide6.QtGui.QKeySequence.StandardKey, str, int], /) -> PySide6.QtGui.QAction
    addAction(self, icon: Union[PySide6.QtGui.QIcon, PySide6.QtGui.QPixmap], text: str, shortcut: Union[PySide6.QtGui.QKeySequence, PySide6.QtCore.QKeyCombination, PySide6.QtGui.QKeySequence.StandardKey, str, int], /) -> PySide6.QtGui.QAction
    addAction(self, icon: Union[PySide6.QtGui.QIcon, PySide6.QtGui.QPixmap], text: str, shortcut: Union[PySide6.QtGui.QKeySequence, PySide6.QtCore.QKeyCombination, PySide6.QtGui.QKeySequence.StandardKey, str, int], receiver: PySide6.QtCore.QObject, member: Union[bytes, bytearray, memoryview], /, type: PySide6.QtCore.Qt.ConnectionType = Instance(Qt.AutoConnection)) -> PySide6.QtGui.QAction
    addAction(self, icon: Union[PySide6.QtGui.QIcon, PySide6.QtGui.QPixmap], text: str, shortcut: Union[PySide6.QtGui.QKeySequence, PySide6.QtCore.QKeyCombination, PySide6.QtGui.QKeySequence.StandardKey, str, int], callable: object, /) -> PySide6.QtGui.QAction
    addAction(self, icon: Union[PySide6.QtGui.QIcon, PySide6.QtGui.QPixmap], text: str, callable: object, /) -> PySide6.QtGui.QAction
    addAction(self, arg__1: Union[PySide6.QtGui.QIcon, PySide6.QtGui.QPixmap], text: str, arg__3: object, /, shortcut: Union[PySide6.QtGui.QKeySequence, PySide6.QtCore.QKeyCombination, PySide6.QtGui.QKeySequence.StandardKey, str, int, NoneType] = None) -> None

So seems like one missing signature from the ones listed in the OP is passing a QAction instance as arg

@dalthviz dalthviz added this to the v2.5.0 milestone Feb 17, 2026
@beatreichenbach
Copy link
Contributor Author

Okay thanks, I'll add a check for all of them and try to refactor that add_action wrapper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QMenu.add_action() got an unexpected keyword argument 'shortcut'

3 participants

Comments