Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ The following wonderful people contributed directly or indirectly to this projec
- `Sascha <https://github.com/saschalalala>`_
- `Shelomentsev D <https://github.com/shelomentsevd>`_
- `Shivam Saini <https://github.com/shivamsn97>`_
- `Siloé Garcez <https://github.com/roast-lord>`_
- `Simon Schürrle <https://github.com/SitiSchu>`_
- `sooyhwang <https://github.com/sooyhwang>`_
- `syntx <https://github.com/syntx>`_
Expand Down
23 changes: 15 additions & 8 deletions telegram/ext/_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the Application class."""

import asyncio
import contextlib
import inspect
Expand Down Expand Up @@ -45,7 +46,6 @@
Optional,
Sequence,
Set,
Tuple,
Type,
TypeVar,
Union,
Expand Down Expand Up @@ -1420,8 +1420,8 @@ def add_handler(self, handler: BaseHandler[Any, CCT, Any], group: int = DEFAULT_
def add_handlers(
self,
handlers: Union[
Union[List[BaseHandler[Any, CCT, Any]], Tuple[BaseHandler[Any, CCT, Any]]],
Dict[int, Union[List[BaseHandler[Any, CCT, Any]], Tuple[BaseHandler[Any, CCT, Any]]]],
Sequence[BaseHandler[Any, CCT, Any]],
Dict[int, Sequence[BaseHandler[Any, CCT, Any]]],
],
group: Union[int, DefaultValue[int]] = _DEFAULT_0,
) -> None:
Expand All @@ -1431,10 +1431,15 @@ def add_handlers(
.. versionadded:: 20.0

Args:
handlers (List[:class:`telegram.ext.BaseHandler`] | \
Dict[int, List[:class:`telegram.ext.BaseHandler`]]): \
handlers (Sequence[:class:`telegram.ext.BaseHandler`] | \
Dict[int, Sequence[:class:`telegram.ext.BaseHandler`]]):
Specify a sequence of handlers *or* a dictionary where the keys are groups and
values are handlers.

.. versionchanged:: NEXT.VERSION
Accepts any :class:`collections.abc.Sequence` as input instead of just a list
or tuple.

group (:obj:`int`, optional): Specify which group the sequence of :paramref:`handlers`
should be added to. Defaults to ``0``.

Expand All @@ -1453,13 +1458,15 @@ def add_handlers(

if isinstance(handlers, dict):
for handler_group, grp_handlers in handlers.items():
if not isinstance(grp_handlers, (list, tuple)):
raise TypeError(f"Handlers for group {handler_group} must be a list or tuple")
if not isinstance(grp_handlers, Sequence):
raise TypeError(
f"Handlers for group {handler_group} must be a sequence of handlers."
)

for handler in grp_handlers:
self.add_handler(handler, handler_group)

elif isinstance(handlers, (list, tuple)):
elif isinstance(handlers, Sequence):
for handler in handlers:
self.add_handler(handler, DefaultValue.get_value(group))

Expand Down