-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Description
This issue is here to expose to the community a proposed design for the Handlers callback prototype.
We have recently closed/rejected PR #859 in this subject as we preferred to go in a different direction. Here we intend to discuss with the community what will be the chosen design.
Current situation:
Minimal callback prototype is def callback(bot, update).
If users require more data/facilities they can initialize the Handler with extra pass_ (bool) arguments which mandates the callback to accept more arguments (like groups, args and others).
Problems:
- The API is very cumbersome and confusing for new users.
- Adding/pushing new context data into the callbacks requires code changes from the users.
Lets say that we want the RegexHandler to provide the match object to the callback. With the current design it will be impossible to add that information without changing the callback prototype and (most likely) impose a newpass_parameter during Handler initialization.
Proposed API
IMPORTANT: This change is non backward compatible. We might implement a backward compatibility layer for a certain period like we have done with other deprecated mechanisms in the past.
- Deprecate
pass_arguments when initializing Handlers. - Handler callbacks prototype will change to:
def callback(update, ctx). - The above
ctxwill be a context of all information/facilities that users may need. The context will be a Mixin of various context objects, depending on the Handler.
Examples of such information/facilities:botupdate_queuejob_queue(something to think about: instead of updater_queue & job_queue, pass theupdater)user_datachat_datamatch(instead ofgroups,groups_dictand similar for).