Make dispatcher use one context per update#1283
Merged
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
jsmnbom
requested changes
Nov 1, 2018
Member
jsmnbom
left a comment
There was a problem hiding this comment.
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?
Member
Author
|
Member
|
Member
|
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It gives user the option to
overloadcontext with their own properties in a lower group handler if they like