fix: fix callback of throttled/debounced decorated functions with mismatched args (#184)

* fix: fix throttled inspection

* build: change typing-ext deps

* fix: use inspect.signature

* use get_max_args

* fix: fix typing
This commit is contained in:
Talley Lambert
2023-08-17 11:05:02 -04:00
committed by GitHub
parent 1da26ce7c2
commit 64dfb43d9e
4 changed files with 88 additions and 71 deletions

View File

@@ -1,5 +1,8 @@
from unittest.mock import Mock
import pytest
from qtpy.QtCore import QObject, Signal
from superqt.utils import qdebounced, qthrottled
@@ -41,3 +44,29 @@ def test_throttled(qtbot):
qtbot.wait(5)
assert mock1.call_count == 2
assert mock2.call_count == 10
@pytest.mark.parametrize("deco", [qthrottled, qdebounced])
def test_ensure_throttled_sig_inspection(deco, qtbot):
mock = Mock()
class Emitter(QObject):
sig = Signal(int, int, int)
@deco
def func(a: int, b: int):
"""docstring"""
mock(a, b)
obj = Emitter()
obj.sig.connect(func)
# this is the crux of the test...
# we emit 3 args, but the function only takes 2
# this should normally work fine in Qt.
# testing here that the decorator doesn't break it.
with qtbot.waitSignal(func.triggered, timeout=1000):
obj.sig.emit(1, 2, 3)
mock.assert_called_once_with(1, 2)
assert func.__doc__ == "docstring"
assert func.__name__ == "func"