mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-29 09:40:31 +01:00
Remove deprecated code (#1012)
* JobQueue: Remove deprecated prevent_autostart & put() * Bot, Updater: Remove deprecated network_delay * Remove deprecated Message.new_chat_member closes #795
This commit is contained in:
parent
36a93e0636
commit
3762792cca
7 changed files with 5 additions and 79 deletions
|
@ -1707,7 +1707,6 @@ class Bot(TelegramObject):
|
||||||
offset=None,
|
offset=None,
|
||||||
limit=100,
|
limit=100,
|
||||||
timeout=0,
|
timeout=0,
|
||||||
network_delay=None,
|
|
||||||
read_latency=2.,
|
read_latency=2.,
|
||||||
allowed_updates=None,
|
allowed_updates=None,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
|
@ -1751,10 +1750,6 @@ class Bot(TelegramObject):
|
||||||
"""
|
"""
|
||||||
url = '{0}/getUpdates'.format(self.base_url)
|
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}
|
data = {'timeout': timeout}
|
||||||
|
|
||||||
if offset:
|
if offset:
|
||||||
|
|
|
@ -277,7 +277,7 @@ class Filters(object):
|
||||||
return bool(message.new_chat_members)
|
return bool(message.new_chat_members)
|
||||||
|
|
||||||
new_chat_members = _NewChatMembers()
|
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):
|
class _LeftChatMember(BaseFilter):
|
||||||
name = 'Filters.status_update.left_chat_member'
|
name = 'Filters.status_update.left_chat_member'
|
||||||
|
@ -368,7 +368,7 @@ class Filters(object):
|
||||||
"""Subset for messages containing a status update.
|
"""Subset for messages containing a status update.
|
||||||
|
|
||||||
Examples:
|
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.
|
``Filters.status_update`` for all status update messages.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
|
@ -384,7 +384,7 @@ class Filters(object):
|
||||||
:attr:`telegram.Message.migrate_from_chat_id` or
|
:attr:`telegram.Message.migrate_from_chat_id` or
|
||||||
:attr: `telegram.Message.migrate_from_chat_id`.
|
:attr: `telegram.Message.migrate_from_chat_id`.
|
||||||
new_chat_members (:obj:`Filter`): Messages that contain
|
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
|
new_chat_photo (:obj:`Filter`): Messages that contain
|
||||||
:attr:`telegram.Message.new_chat_photo`.
|
:attr:`telegram.Message.new_chat_photo`.
|
||||||
new_chat_title (:obj:`Filter`): Messages that contain
|
new_chat_title (:obj:`Filter`): Messages that contain
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
import warnings
|
|
||||||
import datetime
|
import datetime
|
||||||
import weakref
|
import weakref
|
||||||
from numbers import Number
|
from numbers import Number
|
||||||
|
@ -43,16 +42,9 @@ class JobQueue(object):
|
||||||
Args:
|
Args:
|
||||||
bot (:class:`telegram.Bot`): The bot instance that should be passed to the jobs.
|
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):
|
def __init__(self, bot):
|
||||||
if prevent_autostart is not None:
|
|
||||||
warnings.warn("prevent_autostart is being deprecated, use `start` method instead.")
|
|
||||||
|
|
||||||
self._queue = PriorityQueue()
|
self._queue = PriorityQueue()
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.logger = logging.getLogger(self.__class__.__name__)
|
self.logger = logging.getLogger(self.__class__.__name__)
|
||||||
|
@ -63,37 +55,6 @@ class JobQueue(object):
|
||||||
self._next_peek = None
|
self._next_peek = None
|
||||||
self._running = False
|
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):
|
def _put(self, job, next_t=None, last_t=None):
|
||||||
if next_t is None:
|
if next_t is None:
|
||||||
next_t = job.interval
|
next_t = job.interval
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import ssl
|
import ssl
|
||||||
import warnings
|
|
||||||
from threading import Thread, Lock, current_thread, Event
|
from threading import Thread, Lock, current_thread, Event
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -157,7 +156,6 @@ class Updater(object):
|
||||||
def start_polling(self,
|
def start_polling(self,
|
||||||
poll_interval=0.0,
|
poll_interval=0.0,
|
||||||
timeout=10,
|
timeout=10,
|
||||||
network_delay=None,
|
|
||||||
clean=False,
|
clean=False,
|
||||||
bootstrap_retries=0,
|
bootstrap_retries=0,
|
||||||
read_latency=2.,
|
read_latency=2.,
|
||||||
|
@ -182,18 +180,11 @@ class Updater(object):
|
||||||
read_latency (:obj:`float` | :obj:`int`, optional): Grace time in seconds for receiving
|
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
|
the reply from server. Will be added to the `timeout` value and used as the read
|
||||||
timeout from server (Default: 2).
|
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:
|
Returns:
|
||||||
:obj:`Queue`: The update queue that can be filled from the main thread.
|
: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:
|
with self.__lock:
|
||||||
if not self.running:
|
if not self.running:
|
||||||
self.running = True
|
self.running = True
|
||||||
|
|
|
@ -24,7 +24,6 @@ from telegram import (Audio, Contact, Document, Chat, Location, PhotoSize, Stick
|
||||||
User, Video, Voice, Venue, MessageEntity, Game, Invoice, SuccessfulPayment,
|
User, Video, Voice, Venue, MessageEntity, Game, Invoice, SuccessfulPayment,
|
||||||
VideoNote)
|
VideoNote)
|
||||||
from telegram import ParseMode
|
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
|
from telegram.utils.helpers import escape_html, escape_markdown, to_timestamp, from_timestamp
|
||||||
|
|
||||||
_UNDEFINED = object()
|
_UNDEFINED = object()
|
||||||
|
@ -99,9 +98,6 @@ class Message(TelegramObject):
|
||||||
in channels.
|
in channels.
|
||||||
bot (:class:`telegram.Bot`): Optional. The Bot to use for instance methods.
|
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:
|
Args:
|
||||||
message_id (:obj:`int`): Unique message identifier inside this chat.
|
message_id (:obj:`int`): Unique message identifier inside this chat.
|
||||||
from_user (:class:`telegram.User`, optional): Sender, can be empty for messages sent
|
from_user (:class:`telegram.User`, optional): Sender, can be empty for messages sent
|
||||||
|
@ -234,7 +230,6 @@ class Message(TelegramObject):
|
||||||
contact=None,
|
contact=None,
|
||||||
location=None,
|
location=None,
|
||||||
venue=None,
|
venue=None,
|
||||||
new_chat_member=None,
|
|
||||||
left_chat_member=None,
|
left_chat_member=None,
|
||||||
new_chat_title=None,
|
new_chat_title=None,
|
||||||
new_chat_photo=None,
|
new_chat_photo=None,
|
||||||
|
@ -279,7 +274,6 @@ class Message(TelegramObject):
|
||||||
self.contact = contact
|
self.contact = contact
|
||||||
self.location = location
|
self.location = location
|
||||||
self.venue = venue
|
self.venue = venue
|
||||||
self._new_chat_member = new_chat_member
|
|
||||||
self.new_chat_members = new_chat_members or list()
|
self.new_chat_members = new_chat_members or list()
|
||||||
self.left_chat_member = left_chat_member
|
self.left_chat_member = left_chat_member
|
||||||
self.new_chat_title = new_chat_title
|
self.new_chat_title = new_chat_title
|
||||||
|
@ -336,7 +330,6 @@ class Message(TelegramObject):
|
||||||
data['contact'] = Contact.de_json(data.get('contact'), bot)
|
data['contact'] = Contact.de_json(data.get('contact'), bot)
|
||||||
data['location'] = Location.de_json(data.get('location'), bot)
|
data['location'] = Location.de_json(data.get('location'), bot)
|
||||||
data['venue'] = Venue.de_json(data.get('venue'), 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['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['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)
|
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]
|
data['caption_entities'] = [e.to_dict() for e in self.caption_entities]
|
||||||
if self.new_chat_photo:
|
if self.new_chat_photo:
|
||||||
data['new_chat_photo'] = [p.to_dict() for p in 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:
|
if self.new_chat_members:
|
||||||
data['new_chat_members'] = [u.to_dict() for u in 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)
|
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
|
|
||||||
|
|
|
@ -216,9 +216,6 @@ class TestJobQueue(object):
|
||||||
|
|
||||||
def test_warnings(self, job_queue):
|
def test_warnings(self, job_queue):
|
||||||
j = Job(self.job_run_once, repeat=False)
|
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'):
|
with pytest.raises(ValueError, match='can not be set to'):
|
||||||
j.repeat = True
|
j.repeat = True
|
||||||
j.interval = 15
|
j.interval = 15
|
||||||
|
|
|
@ -28,11 +28,7 @@ from telegram.vendor.ptb_urllib3 import urllib3
|
||||||
import telegram
|
import telegram
|
||||||
|
|
||||||
IGNORED_OBJECTS = ('ResponseParameters', 'CallbackGame')
|
IGNORED_OBJECTS = ('ResponseParameters', 'CallbackGame')
|
||||||
IGNORED_PARAMETERS = {'self', 'args', 'kwargs', 'read_latency', 'network_delay', 'timeout', 'bot',
|
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.
|
|
||||||
|
|
||||||
|
|
||||||
def find_next_sibling_until(tag, name, until):
|
def find_next_sibling_until(tag, name, until):
|
||||||
|
|
Loading…
Add table
Reference in a new issue