Skip to content

Commit 9bfac1d

Browse files
committed
Fix: ButtonItem callback compatibility - check parameter count before passing trigger
Fixes critical regression from v3.13.2 where all ButtonItem callbacks were unconditionally passed a 5th parameter (trigger_auto_apply), breaking existing callbacks that only accept 4 parameters. Uses inspect.signature() to check callback parameter count at runtime: - Callbacks with < 5 parameters: receive standard 4 args (backward compatible) - Callbacks with >= 5 parameters: receive trigger_auto_apply as 5th arg This maintains full backward compatibility while enabling the auto-apply feature for DictItem/FloatArrayItem editors when callbacks opt-in by accepting the 5th parameter. Fixes: TypeError: callback() takes 4 positional arguments but 5 were given
1 parent eab8470 commit 9bfac1d

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog #
22

3+
## Version 3.13.3 ##
4+
5+
🛠️ Bug fixes:
6+
7+
* **ButtonItem callbacks**: Fixed critical regression breaking callbacks with 4 parameters
8+
* In v3.13.2, the auto-apply feature unconditionally passed a 5th parameter (`trigger_auto_apply`) to all ButtonItem callbacks
9+
* This broke all existing callbacks expecting only 4 parameters (instance, item, value, parent)
10+
* Now uses `inspect.signature()` to check callback parameter count at runtime
11+
* Callbacks with fewer than 5 parameters receive only the standard 4 arguments
12+
* Callbacks with 5+ parameters receive the additional `trigger_auto_apply` function
13+
* Maintains full backward compatibility while supporting the new auto-apply feature
14+
* Fixes `TypeError: callback() takes 4 positional arguments but 5 were given`
15+
316
## Version 3.13.2 ##
417

518
✨ New features:

guidata/dataset/qtitemwidgets.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from __future__ import annotations
1919

2020
import datetime
21+
import inspect
2122
import os
2223
import os.path as osp
2324
import sys
@@ -1555,14 +1556,24 @@ def clicked(self, *args) -> None:
15551556
"""
15561557
self.parent_layout.update_dataitems()
15571558
callback = self.item.get_prop_value("display", "callback")
1558-
# Pass auto-apply trigger function as optional 5th parameter
1559-
self.cb_value = callback(
1560-
self.item.instance,
1561-
self.item.item,
1562-
self.cb_value,
1563-
self.button.parent(),
1564-
self._trigger_auto_apply,
1565-
)
1559+
# Pass auto-apply trigger function as optional 5th parameter, only if callback
1560+
# takes 5 parameters:
1561+
sig = inspect.signature(callback)
1562+
if len(sig.parameters) < 5:
1563+
self.cb_value = callback(
1564+
self.item.instance,
1565+
self.item.item,
1566+
self.cb_value,
1567+
self.button.parent(),
1568+
)
1569+
else:
1570+
self.cb_value = callback(
1571+
self.item.instance,
1572+
self.item.item,
1573+
self.cb_value,
1574+
self.button.parent(),
1575+
self._trigger_auto_apply,
1576+
)
15661577
self.set()
15671578
self.parent_layout.update_widgets()
15681579
self.notify_value_change()

0 commit comments

Comments
 (0)