From 62f514f068a36316ea790c1f8c40a4f45acef0db Mon Sep 17 00:00:00 2001 From: Bibo-Joshi Date: Sun, 26 Jan 2020 21:55:00 +0100 Subject: [PATCH] CallbackContext: Expose dispatcher as a property (#1684) Co-authored-by: Poolitzer <25934244+Poolitzer@users.noreply.github.com> --- telegram/ext/callbackcontext.py | 14 +++++++++++++- tests/test_callbackcontext.py | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/telegram/ext/callbackcontext.py b/telegram/ext/callbackcontext.py index aeb3eb964..83dd3912a 100644 --- a/telegram/ext/callbackcontext.py +++ b/telegram/ext/callbackcontext.py @@ -44,7 +44,14 @@ class CallbackContext(object): Attributes: chat_data (:obj:`dict`, optional): A dict that can be used to keep any data in. For each - update from the same chat it will be the same ``dict``. + update from the same chat id it will be the same ``dict``. + + Warning: + When a group chat migrates to a supergroup, its chat id will change and the + ``chat_data`` needs to be transferred. For details see our `wiki page + `_. + user_data (:obj:`dict`, optional): A dict that can be used to keep any data in. For each update from the same user it will be the same ``dict``. matches (List[:obj:`re match object`], optional): If the associated update originated from @@ -80,6 +87,11 @@ class CallbackContext(object): self.error = None self.job = None + @property + def dispatcher(self): + """:class:`telegram.ext.Dispatcher`: The dispatcher associated with this context.""" + return self._dispatcher + @property def chat_data(self): return self._chat_data diff --git a/tests/test_callbackcontext.py b/tests/test_callbackcontext.py index 2eefddaf8..5607fda0d 100644 --- a/tests/test_callbackcontext.py +++ b/tests/test_callbackcontext.py @@ -117,3 +117,7 @@ class TestCallbackContext(object): callback_context.user_data = {} with pytest.raises(AttributeError): callback_context.chat_data = "test" + + def test_dispatcher_attribute(self, cdp): + callback_context = CallbackContext(cdp) + assert callback_context.dispatcher == cdp