mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-28 19:22:54 +01:00
CallbackContext: Expose dispatcher as a property (#1684)
Co-authored-by: Poolitzer <25934244+Poolitzer@users.noreply.github.com>
This commit is contained in:
parent
08bbeca8ec
commit
62f514f068
2 changed files with 17 additions and 1 deletions
|
@ -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
|
||||
<https://github.com/python-telegram-bot/python-telegram-bot/wiki/
|
||||
Storing-user--and-chat-related-data#chat-migration>`_.
|
||||
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue