Problem
When we add a function with *args to the WebhookHandler,
WebhookHandler calls the function with 0 args.
It causes some problems when we use ordinary wrapped functions with a decorator.
An example of this is as follows.
import functools
from linebot import WebhookHandler
def with_log(f):
@functools.wraps(f)
def _decorator(*args):
log(f"args: {args}")
return f(*args)
return _decorator
handler = WebhookHandler(...)
@handler.add(...)
@with_log
def example_handler(event):
pass
This program raises the following exception when this example_handler is called.
TypeError: example_handler() missing 1 required positional argument: 'event'
This is because of WebhookHandler.__get_args_count does not care about *args in the parameters.
Solution
Fix WebhookHandler.__get_args_count as follows.
If the added handler function has *args in its parameters, __get_args_count returns 2.