Use same function for hooks with different signatures

I’ve written a simple add-on to show current review progress in anki dock launcher. I’ve used 3 hooks to trigger updates, two of them require no parameters, but one of them requires one. So, I had to introduce a helper callback function to invoke the main set_progress one. Is there a better way to deal with the issue?
The code can be found at https://github.com/k-kirill/anki-libunity/blob/master/anki_libunity/init.py

How about using a lambda expression with an unused parameter if needed, or defining the function with an arbitrary number of arguments?

def set_progress():
gui_hooks.reviewer_did_show_question.append(lambda _: set_progress())

or

def set_progress(*args):
gui_hooks.reviewer_did_show_question.append(set_progress)
3 Likes

I think @hkr’s solution with the lambda function is the way to go, but here’s another possibility just for fun:

def set_progress(_=0):
    ...
3 Likes

Thank you so much for your help. I’ve committed the change using the lambda function as the solution.
P.S. I have zero knowledge in Python and my coding skills are rusty to put it mildly and lambda functions have never been a part of my baggage :slight_smile:

2 Likes