You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unexpected keyword arguments are silently ignored when their names are in TRIGGER_KWARGS #905
EvalFunc.call raises TypeError for unexpected keyword arguments, except for names in the hard-coded TRIGGER_KWARGS set (context, event_type, old_value, payload, payload_obj, qos, request, retain, topic, trigger_type, trigger_time, var_name, value, webhook_id). These are silently dropped in every call of a pyscript function, not only in calls made by triggers:
defnotify(message, title="pyscript"):
returnf"{title}: {message}"notify("door open", topic="alerts") # -> "pyscript: door open", topic is silently droppednotify("door open", topics="alerts") # -> TypeError: notify() called with unexpected keyword arguments: topics
In Python both calls raise TypeError.
Trigger functions no longer need the list: the decorator manager passes them only the kwargs they declare (#870, and #899 for @service). Now only decorator wrappers rely on it, because they pass **kwargs on to the wrapped function:
An upcoming PR keeps the current behaviour, but logs a warning once per function when keyword arguments are ignored because of TRIGGER_KWARGS. The warning links to this issue:
door_opened() was called with keyword arguments it doesn't declare: context, old_value, trigger_type, value, var_name; ...
After a few releases, TRIGGER_KWARGS will be removed and such calls will raise TypeError as in Python.
How to fix your code
Ordinary call: remove the argument, or add the parameter to the function.
Function under a decorator wrapper: declare the kwargs it uses, or add **kwargs:
Activity