-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make dispatcher use one context per update #1283
Conversation
It gives user the option to `overload` context with their own properties in a lower group handler if they like
2f13c82
to
f3f9e8d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. A bit cluttered with the flake8 stuff (would've been nice to merge that to master first, so our builds there don't fail all the time, but mweh)
- We should document this behaviour somewhere.
- Should context maybe be reset after each handler? Like resetting only the standard attributes. It just feels a bit strange to me that (using test_one_context_per_update as example) I would be able to access context.matches in two, even though it does not have a regex filter (and therefore no matches).
- This is all still threadsafe right?
|
|
Okay, so this feature simply doesn't work with Test code to show not working/working (uncomment/comment the # @run_async
def a(u, c: CallbackContext):
print(c)
c.q = 1
# @run_async
def b(u, c: CallbackContext):
print(c)
u = Updater(token, use_context=True)
d = u.dispatcher
d.add_handler(MessageHandler(Filters.all, b))
d.add_handler(MessageHandler(Filters.all, a), -1)
u.update_queue.put(Update(0, message=Message(0, None, None, None)))
u.start_polling()
u.idle() |
- Add note about how you can add custom attributes to context. - Add warnings about how run_async and custom attributes should not be used together.
It gives user the option to
overload
context with their own properties in a lower group handler if they like