Make context-based callbacks the default setting (#2050)

This commit is contained in:
Hinrich Mahler 2020-08-16 16:36:05 +02:00 committed by Bibo-Joshi
parent 3842846b2d
commit b07e42ef33
5 changed files with 12 additions and 13 deletions

View file

@ -117,10 +117,9 @@ class Dispatcher:
``@run_async`` decorator and :meth:`run_async`. Defaults to 4. ``@run_async`` decorator and :meth:`run_async`. Defaults to 4.
persistence (:class:`telegram.ext.BasePersistence`, optional): The persistence class to persistence (:class:`telegram.ext.BasePersistence`, optional): The persistence class to
store data that should be persistent over restarts. store data that should be persistent over restarts.
use_context (:obj:`bool`, optional): If set to :obj:`True` Use the context based use_context (:obj:`bool`, optional): If set to :obj:`True` uses the context based callback
callback API. API (ignored if `dispatcher` argument is used). Defaults to :obj:`True`.
During the deprecation period of the old API the default is :obj:`False`. **New users**: set this to :obj:`True`.
**New users**: Set this to :obj:`True`.
""" """
@ -136,7 +135,7 @@ class Dispatcher:
exception_event=None, exception_event=None,
job_queue=None, job_queue=None,
persistence=None, persistence=None,
use_context=False): use_context=True):
self.bot = bot self.bot = bot
self.update_queue = update_queue self.update_queue = update_queue
self.job_queue = job_queue self.job_queue = job_queue

View file

@ -82,9 +82,9 @@ class Updater:
`telegram.utils.request.Request` object (ignored if `bot` or `dispatcher` argument is `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 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. control the default timeouts and/or control the proxy used for http communication.
use_context (:obj:`bool`, optional): If set to :obj:`True` Use the context based callback use_context (:obj:`bool`, optional): If set to :obj:`True` uses the context based callback
API (ignored if :attr:`dispatcher` argument is used). During the deprecation period of API (ignored if `dispatcher` argument is used). Defaults to :obj:`True`.
the old API the default is :obj:`False`. **New users**: set this to :obj:`True`. **New users**: set this to :obj:`True`.
persistence (:class:`telegram.ext.BasePersistence`, optional): The persistence class to persistence (:class:`telegram.ext.BasePersistence`, optional): The persistence class to
store data that should be persistent over restarts (ignored if `dispatcher` argument is store data that should be persistent over restarts (ignored if `dispatcher` argument is
used). used).
@ -114,7 +114,7 @@ class Updater:
request_kwargs=None, request_kwargs=None,
persistence=None, persistence=None,
defaults=None, defaults=None,
use_context=False, use_context=True,
dispatcher=None, dispatcher=None,
base_file_url=None): base_file_url=None):

View file

@ -143,7 +143,7 @@ def cdp(dp):
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def updater(bot): def updater(bot):
up = Updater(bot=bot, workers=2) up = Updater(bot=bot, workers=2, use_context=False)
yield up yield up
if up.running: if up.running:
up.stop() up.stop()

View file

@ -480,7 +480,7 @@ class TestDispatcher:
assert passed == ['start1', 'error', err, 'start3'] assert passed == ['start1', 'error', err, 'start3']
assert passed[2] is err 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 = [] increment = []
class OwnPersistence(BasePersistence): class OwnPersistence(BasePersistence):
@ -530,7 +530,7 @@ class TestDispatcher:
length=len('/start'))], length=len('/start'))],
bot=bot)) bot=bot))
my_persistence = OwnPersistence() 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_handler(CommandHandler('start', start1))
dp.add_error_handler(error) dp.add_error_handler(error)
dp.process_update(update) dp.process_update(update)

View file

@ -217,7 +217,7 @@ class TestJobQueue:
assert self.result == 1 assert self.result == 1
def test_in_updater(self, bot): def test_in_updater(self, bot):
u = Updater(bot=bot) u = Updater(bot=bot, use_context=False)
u.job_queue.start() u.job_queue.start()
try: try:
u.job_queue.run_repeating(self.job_run_once, 0.02) u.job_queue.run_repeating(self.job_run_once, 0.02)