pyapp-kit / superqt

Missing widgets and components for Qt-python
https://pyapp-kit.github.io/superqt/
BSD 3-Clause "New" or "Revised" License
210 stars 38 forks source link

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

Closed tlambert03 closed 1 year ago

tlambert03 commented 1 year ago

similar to #183, this fixes calling a qdebounced/qthrottled function with too many arguments

class Emitter(QObject):
    sig = Signal(int, int, int)

@qdebounced
def func(a: int, b: int):
    ...

obj = Emitter()
obj.sig.connect(func)
obj.sig.emit(1, 2, 3)  # currently breaks, too many args

I had to do it manually here (meaning pass func(*args[:max_args])), because of a bug in pyside that prevents proper inspection of callable objects: https://bugreports.qt.io/browse/PYSIDE-2423

This PR also changes the decorator pattern to return an instance of ThrottledCallable (whereas before it just returned an object that implemented the protocol). I think it makes for a much clearer read

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.76% :warning:

Comparison is base (41ea4e8) 86.05% compared to head (aac1d14) 85.29%. Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #184 +/- ## ========================================== - Coverage 86.05% 85.29% -0.76% ========================================== Files 36 36 Lines 2746 2747 +1 ========================================== - Hits 2363 2343 -20 - Misses 383 404 +21 ``` | [Files Changed](https://app.codecov.io/gh/pyapp-kit/superqt/pull/184?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyapp-kit) | Coverage Δ | | |---|---|---| | [src/superqt/utils/\_throttler.py](https://app.codecov.io/gh/pyapp-kit/superqt/pull/184?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyapp-kit#diff-c3JjL3N1cGVycXQvdXRpbHMvX3Rocm90dGxlci5weQ==) | `89.62% <100.00%> (+0.40%)` | :arrow_up: | ... and [9 files with indirect coverage changes](https://app.codecov.io/gh/pyapp-kit/superqt/pull/184/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyapp-kit)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.