From 3762792ccad9c56d7798743e33924ba1214d862f Mon Sep 17 00:00:00 2001 From: Noam Meltzer Date: Thu, 22 Feb 2018 14:17:06 +0200 Subject: [PATCH] Remove deprecated code (#1012) * JobQueue: Remove deprecated prevent_autostart & put() * Bot, Updater: Remove deprecated network_delay * Remove deprecated Message.new_chat_member closes #795 --- telegram/bot.py | 5 ----- telegram/ext/filters.py | 6 +++--- telegram/ext/jobqueue.py | 41 +--------------------------------------- telegram/ext/updater.py | 9 --------- telegram/message.py | 14 -------------- tests/test_jobqueue.py | 3 --- tests/test_official.py | 6 +----- 7 files changed, 5 insertions(+), 79 deletions(-) diff --git a/telegram/bot.py b/telegram/bot.py index 0664c5b10..4aac1d138 100644 --- a/telegram/bot.py +++ b/telegram/bot.py @@ -1707,7 +1707,6 @@ class Bot(TelegramObject): offset=None, limit=100, timeout=0, - network_delay=None, read_latency=2., allowed_updates=None, **kwargs): @@ -1751,10 +1750,6 @@ class Bot(TelegramObject): """ url = '{0}/getUpdates'.format(self.base_url) - if network_delay is not None: - warnings.warn('network_delay is deprecated, use read_latency instead') - read_latency = network_delay - data = {'timeout': timeout} if offset: diff --git a/telegram/ext/filters.py b/telegram/ext/filters.py index 0f244da14..7fa78c225 100644 --- a/telegram/ext/filters.py +++ b/telegram/ext/filters.py @@ -277,7 +277,7 @@ class Filters(object): return bool(message.new_chat_members) new_chat_members = _NewChatMembers() - """:obj:`Filter`: Messages that contain :attr:`telegram.Message.new_chat_member`.""" + """:obj:`Filter`: Messages that contain :attr:`telegram.Message.new_chat_members`.""" class _LeftChatMember(BaseFilter): name = 'Filters.status_update.left_chat_member' @@ -368,7 +368,7 @@ class Filters(object): """Subset for messages containing a status update. Examples: - Use these filters like: ``Filters.status_update.new_chat_member`` etc. Or use just + Use these filters like: ``Filters.status_update.new_chat_members`` etc. Or use just ``Filters.status_update`` for all status update messages. Attributes: @@ -384,7 +384,7 @@ class Filters(object): :attr:`telegram.Message.migrate_from_chat_id` or :attr: `telegram.Message.migrate_from_chat_id`. new_chat_members (:obj:`Filter`): Messages that contain - :attr:`telegram.Message.new_chat_member`. + :attr:`telegram.Message.new_chat_members`. new_chat_photo (:obj:`Filter`): Messages that contain :attr:`telegram.Message.new_chat_photo`. new_chat_title (:obj:`Filter`): Messages that contain diff --git a/telegram/ext/jobqueue.py b/telegram/ext/jobqueue.py index 4fc7b244c..1aa51b03f 100644 --- a/telegram/ext/jobqueue.py +++ b/telegram/ext/jobqueue.py @@ -20,7 +20,6 @@ import logging import time -import warnings import datetime import weakref from numbers import Number @@ -43,16 +42,9 @@ class JobQueue(object): Args: bot (:class:`telegram.Bot`): The bot instance that should be passed to the jobs. - Deprecated: - prevent_autostart (:obj:`bool`, optional): Thread does not start during initialisation. - Use `start` method instead. - """ - def __init__(self, bot, prevent_autostart=None): - if prevent_autostart is not None: - warnings.warn("prevent_autostart is being deprecated, use `start` method instead.") - + def __init__(self, bot): self._queue = PriorityQueue() self.bot = bot self.logger = logging.getLogger(self.__class__.__name__) @@ -63,37 +55,6 @@ class JobQueue(object): self._next_peek = None self._running = False - def put(self, job, next_t=None): - """Queue a new job. - - Note: - This method is deprecated. Please use: :attr:`run_once`, :attr:`run_daily` - or :attr:`run_repeating` instead. - - Args: - job (:class:`telegram.ext.Job`): The ``Job`` instance representing the new job. - next_t (:obj:`int` | :obj:`float` | :obj:`datetime.timedelta` | \ - :obj:`datetime.datetime` | :obj:`datetime.time`, optional): - Time in or at which the job should run for the first time. This parameter will - be interpreted depending on its type. - - * :obj:`int` or :obj:`float` will be interpreted as "seconds from now" in which the - job should run. - * :obj:`datetime.timedelta` will be interpreted as "time from now" in which the - job should run. - * :obj:`datetime.datetime` will be interpreted as a specific date and time at - which the job should run. - * :obj:`datetime.time` will be interpreted as a specific time at which the job - should run. This could be either today or, if the time has already passed, - tomorrow. - - """ - warnings.warn("'JobQueue.put' is being deprecated, use 'JobQueue.run_once', " - "'JobQueue.run_daily' or 'JobQueue.run_repeating' instead") - if job.job_queue is None: - job.job_queue = self - self._put(job, next_t=next_t) - def _put(self, job, next_t=None, last_t=None): if next_t is None: next_t = job.interval diff --git a/telegram/ext/updater.py b/telegram/ext/updater.py index 83c421cc6..c711d1be7 100644 --- a/telegram/ext/updater.py +++ b/telegram/ext/updater.py @@ -21,7 +21,6 @@ import logging import os import ssl -import warnings from threading import Thread, Lock, current_thread, Event from time import sleep import subprocess @@ -157,7 +156,6 @@ class Updater(object): def start_polling(self, poll_interval=0.0, timeout=10, - network_delay=None, clean=False, bootstrap_retries=0, read_latency=2., @@ -182,18 +180,11 @@ class Updater(object): read_latency (:obj:`float` | :obj:`int`, optional): Grace time in seconds for receiving the reply from server. Will be added to the `timeout` value and used as the read timeout from server (Default: 2). - network_delay: Deprecated. Will be honoured as :attr:`read_latency` for a while but - will be removed in the future. Returns: :obj:`Queue`: The update queue that can be filled from the main thread. """ - - if network_delay is not None: - warnings.warn('network_delay is deprecated, use read_latency instead') - read_latency = network_delay - with self.__lock: if not self.running: self.running = True diff --git a/telegram/message.py b/telegram/message.py index d36ba32ab..f59b8f44c 100644 --- a/telegram/message.py +++ b/telegram/message.py @@ -24,7 +24,6 @@ from telegram import (Audio, Contact, Document, Chat, Location, PhotoSize, Stick User, Video, Voice, Venue, MessageEntity, Game, Invoice, SuccessfulPayment, VideoNote) from telegram import ParseMode -from telegram.utils.deprecate import warn_deprecate_obj from telegram.utils.helpers import escape_html, escape_markdown, to_timestamp, from_timestamp _UNDEFINED = object() @@ -99,9 +98,6 @@ class Message(TelegramObject): in channels. bot (:class:`telegram.Bot`): Optional. The Bot to use for instance methods. - Deprecated: 6.0 - new_chat_member (:class:`telegram.User`): Replaced with :attr:`new_chat_members` - Args: message_id (:obj:`int`): Unique message identifier inside this chat. from_user (:class:`telegram.User`, optional): Sender, can be empty for messages sent @@ -234,7 +230,6 @@ class Message(TelegramObject): contact=None, location=None, venue=None, - new_chat_member=None, left_chat_member=None, new_chat_title=None, new_chat_photo=None, @@ -279,7 +274,6 @@ class Message(TelegramObject): self.contact = contact self.location = location self.venue = venue - self._new_chat_member = new_chat_member self.new_chat_members = new_chat_members or list() self.left_chat_member = left_chat_member self.new_chat_title = new_chat_title @@ -336,7 +330,6 @@ class Message(TelegramObject): data['contact'] = Contact.de_json(data.get('contact'), bot) data['location'] = Location.de_json(data.get('location'), bot) data['venue'] = Venue.de_json(data.get('venue'), bot) - data['new_chat_member'] = User.de_json(data.get('new_chat_member'), bot) data['new_chat_members'] = User.de_list(data.get('new_chat_members'), bot) data['left_chat_member'] = User.de_json(data.get('left_chat_member'), bot) data['new_chat_photo'] = PhotoSize.de_list(data.get('new_chat_photo'), bot) @@ -401,7 +394,6 @@ class Message(TelegramObject): data['caption_entities'] = [e.to_dict() for e in self.caption_entities] if self.new_chat_photo: data['new_chat_photo'] = [p.to_dict() for p in self.new_chat_photo] - data['new_chat_member'] = data.pop('_new_chat_member', None) if self.new_chat_members: data['new_chat_members'] = [u.to_dict() for u in self.new_chat_members] @@ -1005,9 +997,3 @@ class Message(TelegramObject): """ return self._text_markdown(urled=True) - - @property - def new_chat_member(self): - """Deprecated""" - warn_deprecate_obj('new_chat_member', 'new_chat_members') - return self._new_chat_member diff --git a/tests/test_jobqueue.py b/tests/test_jobqueue.py index 0229a5552..083a3d194 100644 --- a/tests/test_jobqueue.py +++ b/tests/test_jobqueue.py @@ -216,9 +216,6 @@ class TestJobQueue(object): def test_warnings(self, job_queue): j = Job(self.job_run_once, repeat=False) - with pytest.warns(UserWarning): - job_queue.put(j, next_t=0) - j.schedule_removal() with pytest.raises(ValueError, match='can not be set to'): j.repeat = True j.interval = 15 diff --git a/tests/test_official.py b/tests/test_official.py index ecd3a7460..b8afdf745 100644 --- a/tests/test_official.py +++ b/tests/test_official.py @@ -28,11 +28,7 @@ from telegram.vendor.ptb_urllib3 import urllib3 import telegram IGNORED_OBJECTS = ('ResponseParameters', 'CallbackGame') -IGNORED_PARAMETERS = {'self', 'args', 'kwargs', 'read_latency', 'network_delay', 'timeout', 'bot', - 'new_chat_member'} - - -# TODO: New_chat_member is still in our lib but already removed from TG's docs. +IGNORED_PARAMETERS = {'self', 'args', 'kwargs', 'read_latency', 'network_delay', 'timeout', 'bot'} def find_next_sibling_until(tag, name, until):