Skip to content

Commit d216aab

Browse files
nemacystscuevasrja
authored andcommitted
Allow Sequence Input for allowed_updates in Application and Updater Methods (python-telegram-bot#4589)
1 parent 10deb18 commit d216aab

3 files changed

Lines changed: 28 additions & 14 deletions

File tree

telegram/_webhookinfo.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# You should have received a copy of the GNU Lesser Public License
1818
# along with this program. If not, see [http://www.gnu.org/licenses/].
1919
"""This module contains an object that represents a Telegram WebhookInfo."""
20+
2021
from collections.abc import Sequence
2122
from datetime import datetime
2223
from typing import TYPE_CHECKING, Optional
@@ -60,7 +61,7 @@ class WebhookInfo(TelegramObject):
6061
most recent error that happened when trying to deliver an update via webhook.
6162
max_connections (:obj:`int`, optional): Maximum allowed number of simultaneous HTTPS
6263
connections to the webhook for update delivery.
63-
allowed_updates (Sequence[:obj:`str`], optional): A list of update types the bot is
64+
allowed_updates (Sequence[:obj:`str`], optional): A sequence of update types the bot is
6465
subscribed to. Defaults to all update types, except
6566
:attr:`telegram.Update.chat_member`.
6667
@@ -90,7 +91,7 @@ class WebhookInfo(TelegramObject):
9091
most recent error that happened when trying to deliver an update via webhook.
9192
max_connections (:obj:`int`): Optional. Maximum allowed number of simultaneous HTTPS
9293
connections to the webhook for update delivery.
93-
allowed_updates (tuple[:obj:`str`]): Optional. A list of update types the bot is
94+
allowed_updates (tuple[:obj:`str`]): Optional. A tuple of update types the bot is
9495
subscribed to. Defaults to all update types, except
9596
:attr:`telegram.Update.chat_member`.
9697

telegram/ext/_application.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ def run_polling(
746746
write_timeout: ODVInput[float] = DEFAULT_NONE,
747747
connect_timeout: ODVInput[float] = DEFAULT_NONE,
748748
pool_timeout: ODVInput[float] = DEFAULT_NONE,
749-
allowed_updates: Optional[list[str]] = None,
749+
allowed_updates: Optional[Sequence[str]] = None,
750750
drop_pending_updates: Optional[bool] = None,
751751
close_loop: bool = True,
752752
stop_signals: ODVInput[Sequence[int]] = DEFAULT_NONE,
@@ -823,8 +823,11 @@ def run_polling(
823823
:meth:`telegram.ext.ApplicationBuilder.get_updates_pool_timeout`.
824824
drop_pending_updates (:obj:`bool`, optional): Whether to clean any pending updates on
825825
Telegram servers before actually starting to poll. Default is :obj:`False`.
826-
allowed_updates (list[:obj:`str`], optional): Passed to
826+
allowed_updates (Sequence[:obj:`str`], optional): Passed to
827827
:meth:`telegram.Bot.get_updates`.
828+
829+
.. versionchanged:: NEXT.VERSION
830+
Accepts any :class:`collections.abc.Sequence` as input instead of just a list
828831
close_loop (:obj:`bool`, optional): If :obj:`True`, the current event loop will be
829832
closed upon shutdown. Defaults to :obj:`True`.
830833
@@ -888,7 +891,7 @@ def run_webhook(
888891
key: Optional[Union[str, Path]] = None,
889892
bootstrap_retries: int = 0,
890893
webhook_url: Optional[str] = None,
891-
allowed_updates: Optional[list[str]] = None,
894+
allowed_updates: Optional[Sequence[str]] = None,
892895
drop_pending_updates: Optional[bool] = None,
893896
ip_address: Optional[str] = None,
894897
max_connections: int = 40,
@@ -954,8 +957,11 @@ def run_webhook(
954957
webhook_url (:obj:`str`, optional): Explicitly specify the webhook url. Useful behind
955958
NAT, reverse proxy, etc. Default is derived from :paramref:`listen`,
956959
:paramref:`port`, :paramref:`url_path`, :paramref:`cert`, and :paramref:`key`.
957-
allowed_updates (list[:obj:`str`], optional): Passed to
960+
allowed_updates (Sequence[:obj:`str`], optional): Passed to
958961
:meth:`telegram.Bot.set_webhook`.
962+
963+
.. versionchanged:: NEXT.VERSION
964+
Accepts any :class:`collections.abc.Sequence` as input instead of just a list
959965
drop_pending_updates (:obj:`bool`, optional): Whether to clean any pending updates on
960966
Telegram servers before actually starting to poll. Default is :obj:`False`.
961967
ip_address (:obj:`str`, optional): Passed to :meth:`telegram.Bot.set_webhook`.

telegram/ext/_updater.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
# You should have received a copy of the GNU Lesser Public License
1818
# along with this program. If not, see [http://www.gnu.org/licenses/].
1919
"""This module contains the class Updater, which tries to make creating Telegram bots intuitive."""
20+
2021
import asyncio
2122
import contextlib
2223
import ssl
23-
from collections.abc import Coroutine
24+
from collections.abc import Coroutine, Sequence
2425
from pathlib import Path
2526
from types import TracebackType
2627
from typing import TYPE_CHECKING, Any, Callable, Optional, TypeVar, Union
@@ -210,7 +211,7 @@ async def start_polling(
210211
write_timeout: ODVInput[float] = DEFAULT_NONE,
211212
connect_timeout: ODVInput[float] = DEFAULT_NONE,
212213
pool_timeout: ODVInput[float] = DEFAULT_NONE,
213-
allowed_updates: Optional[list[str]] = None,
214+
allowed_updates: Optional[Sequence[str]] = None,
214215
drop_pending_updates: Optional[bool] = None,
215216
error_callback: Optional[Callable[[TelegramError], None]] = None,
216217
) -> "asyncio.Queue[object]":
@@ -265,8 +266,11 @@ async def start_polling(
265266
Deprecated in favor of setting the timeout via
266267
:meth:`telegram.ext.ApplicationBuilder.get_updates_pool_timeout` or
267268
:paramref:`telegram.Bot.get_updates_request`.
268-
allowed_updates (list[:obj:`str`], optional): Passed to
269+
allowed_updates (Sequence[:obj:`str`], optional): Passed to
269270
:meth:`telegram.Bot.get_updates`.
271+
272+
.. versionchanged:: NEXT.VERSION
273+
Accepts any :class:`collections.abc.Sequence` as input instead of just a list
270274
drop_pending_updates (:obj:`bool`, optional): Whether to clean any pending updates on
271275
Telegram servers before actually starting to poll. Default is :obj:`False`.
272276
@@ -344,7 +348,7 @@ async def _start_polling(
344348
pool_timeout: ODVInput[float],
345349
bootstrap_retries: int,
346350
drop_pending_updates: Optional[bool],
347-
allowed_updates: Optional[list[str]],
351+
allowed_updates: Optional[Sequence[str]],
348352
ready: asyncio.Event,
349353
error_callback: Optional[Callable[[TelegramError], None]],
350354
) -> None:
@@ -457,7 +461,7 @@ async def start_webhook(
457461
key: Optional[Union[str, Path]] = None,
458462
bootstrap_retries: int = 0,
459463
webhook_url: Optional[str] = None,
460-
allowed_updates: Optional[list[str]] = None,
464+
allowed_updates: Optional[Sequence[str]] = None,
461465
drop_pending_updates: Optional[bool] = None,
462466
ip_address: Optional[str] = None,
463467
max_connections: int = 40,
@@ -516,8 +520,11 @@ async def start_webhook(
516520
Defaults to :obj:`None`.
517521
518522
.. versionadded :: 13.4
519-
allowed_updates (list[:obj:`str`], optional): Passed to
523+
allowed_updates (Sequence[:obj:`str`], optional): Passed to
520524
:meth:`telegram.Bot.set_webhook`. Defaults to :obj:`None`.
525+
526+
.. versionchanged:: NEXT.VERSION
527+
Accepts any :class:`collections.abc.Sequence` as input instead of just a list
521528
max_connections (:obj:`int`, optional): Passed to
522529
:meth:`telegram.Bot.set_webhook`. Defaults to ``40``.
523530
@@ -624,7 +631,7 @@ async def _start_webhook(
624631
port: int,
625632
url_path: str,
626633
bootstrap_retries: int,
627-
allowed_updates: Optional[list[str]],
634+
allowed_updates: Optional[Sequence[str]],
628635
cert: Optional[Union[str, Path]] = None,
629636
key: Optional[Union[str, Path]] = None,
630637
drop_pending_updates: Optional[bool] = None,
@@ -767,7 +774,7 @@ async def _bootstrap(
767774
self,
768775
max_retries: int,
769776
webhook_url: Optional[str],
770-
allowed_updates: Optional[list[str]],
777+
allowed_updates: Optional[Sequence[str]],
771778
drop_pending_updates: Optional[bool] = None,
772779
cert: Optional[bytes] = None,
773780
bootstrap_interval: float = 1,

0 commit comments

Comments
 (0)