From 5eb1f4f6df3e529419f93e437f7e224e337e426c Mon Sep 17 00:00:00 2001 From: Hinrich Mahler Date: Sun, 16 Aug 2020 16:36:05 +0200 Subject: [PATCH 1/3] Make use_context default to True --- telegram/ext/updater.py | 8 ++++---- tests/conftest.py | 2 +- tests/test_jobqueue.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/telegram/ext/updater.py b/telegram/ext/updater.py index 78259660e1a..758cfc0406d 100644 --- a/telegram/ext/updater.py +++ b/telegram/ext/updater.py @@ -82,9 +82,9 @@ class Updater: `telegram.utils.request.Request` object (ignored if `bot` or `dispatcher` argument is used). The request_kwargs are very useful for the advanced users who would like to control the default timeouts and/or control the proxy used for http communication. - use_context (:obj:`bool`, optional): If set to ``True`` Use the context based callback API - (ignored if `dispatcher` argument is used). During the deprecation period of the old - API the default is ``False``. **New users**: set this to ``True``. + use_context (:obj:`bool`, optional): If set to :obj:`True` uses the context based callback + API (ignored if `dispatcher` argument is used). Defaults to :obj:`True`. + **New users**: set this to :obj:`True`. persistence (:class:`telegram.ext.BasePersistence`, optional): The persistence class to store data that should be persistent over restarts (ignored if `dispatcher` argument is used). @@ -114,7 +114,7 @@ def __init__(self, request_kwargs=None, persistence=None, defaults=None, - use_context=False, + use_context=True, dispatcher=None, base_file_url=None): diff --git a/tests/conftest.py b/tests/conftest.py index d957d0d04f0..8518db8cb1e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -143,7 +143,7 @@ def cdp(dp): @pytest.fixture(scope='function') def updater(bot): - up = Updater(bot=bot, workers=2) + up = Updater(bot=bot, workers=2, use_context=False) yield up if up.running: up.stop() diff --git a/tests/test_jobqueue.py b/tests/test_jobqueue.py index 85ebda2e9e7..fe7bc19677b 100644 --- a/tests/test_jobqueue.py +++ b/tests/test_jobqueue.py @@ -217,7 +217,7 @@ def test_error(self, job_queue): assert self.result == 1 def test_in_updater(self, bot): - u = Updater(bot=bot) + u = Updater(bot=bot, use_context=False) u.job_queue.start() try: u.job_queue.run_repeating(self.job_run_once, 0.02) From f3e2b8ee6decd4d3e7de39d0166150d9151dcfd7 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler Date: Sun, 16 Aug 2020 17:08:02 +0200 Subject: [PATCH 2/3] Change the default for Dispatcher, too --- telegram/ext/dispatcher.py | 9 +++++---- tests/test_dispatcher.py | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/telegram/ext/dispatcher.py b/telegram/ext/dispatcher.py index 5c4cdaaf490..39050efec38 100644 --- a/telegram/ext/dispatcher.py +++ b/telegram/ext/dispatcher.py @@ -89,9 +89,9 @@ class Dispatcher: ``@run_async`` decorator. defaults to 4. persistence (:class:`telegram.ext.BasePersistence`, optional): The persistence class to store data that should be persistent over restarts - use_context (:obj:`bool`, optional): If set to ``True`` Use the context based callback API. - During the deprecation period of the old API the default is ``False``. **New users**: - set this to ``True``. + use_context (:obj:`bool`, optional): If set to :obj:`True` uses the context based callback + API (ignored if `dispatcher` argument is used). Defaults to :obj:`True`. + **New users**: set this to :obj:`True`. """ @@ -107,7 +107,7 @@ def __init__(self, exception_event=None, job_queue=None, persistence=None, - use_context=False): + use_context=True): self.bot = bot self.update_queue = update_queue self.job_queue = job_queue @@ -519,6 +519,7 @@ def dispatch_error(self, update, error): """ if self.error_handlers: for callback in self.error_handlers: + print('This is dispatcher. use_context=', self.use_context) if self.use_context: callback(update, CallbackContext.from_error(update, error, self)) else: diff --git a/tests/test_dispatcher.py b/tests/test_dispatcher.py index 26949ddc5dd..e0f31e6f4af 100644 --- a/tests/test_dispatcher.py +++ b/tests/test_dispatcher.py @@ -344,7 +344,7 @@ def error(b, u, e): assert passed == ['start1', 'error', err, 'start3'] assert passed[2] is err - def test_error_while_saving_chat_data(self, dp, bot): + def test_error_while_saving_chat_data(self, bot): increment = [] class OwnPersistence(BasePersistence): @@ -394,7 +394,7 @@ def error(b, u, e): length=len('/start'))], bot=bot)) my_persistence = OwnPersistence() - dp = Dispatcher(bot, None, persistence=my_persistence) + dp = Dispatcher(bot, None, persistence=my_persistence, use_context=False) dp.add_handler(CommandHandler('start', start1)) dp.add_error_handler(error) dp.process_update(update) From 10e481b81ec31246c1bf4919de1edb38f8ce2a54 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler Date: Sun, 16 Aug 2020 19:12:27 +0200 Subject: [PATCH 3/3] Remove debug print --- telegram/ext/dispatcher.py | 1 - 1 file changed, 1 deletion(-) diff --git a/telegram/ext/dispatcher.py b/telegram/ext/dispatcher.py index 39050efec38..cfa1a0f0f0e 100644 --- a/telegram/ext/dispatcher.py +++ b/telegram/ext/dispatcher.py @@ -519,7 +519,6 @@ def dispatch_error(self, update, error): """ if self.error_handlers: for callback in self.error_handlers: - print('This is dispatcher. use_context=', self.use_context) if self.use_context: callback(update, CallbackContext.from_error(update, error, self)) else: