mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-10-24 01:46:22 +02:00
Rename Handler
to BaseHandler
(#3019)
This commit is contained in:
parent
23ed0880d2
commit
65bbea780a
28 changed files with 123 additions and 113 deletions
6
docs/source/telegram.ext.basehandler.rst
Normal file
6
docs/source/telegram.ext.basehandler.rst
Normal file
|
@ -0,0 +1,6 @@
|
|||
telegram.ext.BaseHandler
|
||||
========================
|
||||
|
||||
.. autoclass:: telegram.ext.BaseHandler
|
||||
:members:
|
||||
:show-inheritance:
|
|
@ -1,6 +0,0 @@
|
|||
telegram.ext.Handler
|
||||
====================
|
||||
|
||||
.. autoclass:: telegram.ext.Handler
|
||||
:members:
|
||||
:show-inheritance:
|
|
@ -19,7 +19,7 @@ Handlers
|
|||
|
||||
.. toctree::
|
||||
|
||||
telegram.ext.handler
|
||||
telegram.ext.basehandler
|
||||
telegram.ext.callbackqueryhandler
|
||||
telegram.ext.chatjoinrequesthandler
|
||||
telegram.ext.chatmemberhandler
|
||||
|
|
|
@ -36,7 +36,7 @@ __all__ = (
|
|||
"DictPersistence",
|
||||
"ExtBot",
|
||||
"filters",
|
||||
"Handler",
|
||||
"BaseHandler",
|
||||
"InlineQueryHandler",
|
||||
"InvalidCallbackData",
|
||||
"Job",
|
||||
|
@ -71,7 +71,7 @@ from ._conversationhandler import ConversationHandler
|
|||
from ._defaults import Defaults
|
||||
from ._dictpersistence import DictPersistence
|
||||
from ._extbot import ExtBot
|
||||
from ._handler import Handler
|
||||
from ._handler import BaseHandler
|
||||
from ._inlinequeryhandler import InlineQueryHandler
|
||||
from ._jobqueue import Job, JobQueue
|
||||
from ._messagehandler import MessageHandler
|
||||
|
|
|
@ -56,7 +56,7 @@ from telegram.ext._basepersistence import BasePersistence
|
|||
from telegram.ext._callbackdatacache import CallbackDataCache
|
||||
from telegram.ext._contexttypes import ContextTypes
|
||||
from telegram.ext._extbot import ExtBot
|
||||
from telegram.ext._handler import Handler
|
||||
from telegram.ext._handler import BaseHandler
|
||||
from telegram.ext._updater import Updater
|
||||
from telegram.ext._utils.stack import was_called_by
|
||||
from telegram.ext._utils.trackingdict import TrackingDict
|
||||
|
@ -166,8 +166,8 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AbstractAsyncContextManager)
|
|||
bot_data (:obj:`dict`): A dictionary handlers can use to store data for the bot.
|
||||
persistence (:class:`telegram.ext.BasePersistence`): The persistence class to
|
||||
store data that should be persistent over restarts.
|
||||
handlers (Dict[:obj:`int`, List[:class:`telegram.ext.Handler`]]): A dictionary mapping each
|
||||
handler group to the list of handlers registered to that group.
|
||||
handlers (Dict[:obj:`int`, List[:class:`telegram.ext.BaseHandler`]]): A dictionary mapping
|
||||
each handler group to the list of handlers registered to that group.
|
||||
|
||||
.. seealso::
|
||||
:meth:`add_handler`, :meth:`add_handlers`.
|
||||
|
@ -237,7 +237,7 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AbstractAsyncContextManager)
|
|||
self.job_queue = job_queue
|
||||
self.context_types = context_types
|
||||
self.updater = updater
|
||||
self.handlers: Dict[int, List[Handler]] = {}
|
||||
self.handlers: Dict[int, List[BaseHandler]] = {}
|
||||
self.error_handlers: Dict[Callable, Union[bool, DefaultValue]] = {}
|
||||
|
||||
if isinstance(concurrent_updates, int) and concurrent_updates < 0:
|
||||
|
@ -962,13 +962,14 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AbstractAsyncContextManager)
|
|||
# (in __create_task_callback)
|
||||
self._mark_for_persistence_update(update=update)
|
||||
|
||||
def add_handler(self, handler: Handler[Any, CCT], group: int = DEFAULT_GROUP) -> None:
|
||||
def add_handler(self, handler: BaseHandler[Any, CCT], group: int = DEFAULT_GROUP) -> None:
|
||||
"""Register a handler.
|
||||
|
||||
TL;DR: Order and priority counts. 0 or 1 handlers per group will be used. End handling of
|
||||
update with :class:`telegram.ext.ApplicationHandlerStop`.
|
||||
|
||||
A handler must be an instance of a subclass of :class:`telegram.ext.Handler`. All handlers
|
||||
A handler must be an instance of a subclass of :class:`telegram.ext.BaseHandler`. All
|
||||
handlers
|
||||
are organized in groups with a numeric value. The default group is 0. All groups will be
|
||||
evaluated for handling an update, but only 0 or 1 handler per group will be used. If
|
||||
:class:`telegram.ext.ApplicationHandlerStop` is raised from one of the handlers, no further
|
||||
|
@ -978,7 +979,7 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AbstractAsyncContextManager)
|
|||
|
||||
* Priority of the group (lower group number == higher priority)
|
||||
* The first handler in a group which can handle an update (see
|
||||
:attr:`telegram.ext.Handler.check_update`) will be used. Other handlers from the
|
||||
:attr:`telegram.ext.BaseHandler.check_update`) will be used. Other handlers from the
|
||||
group will not be used. The order in which handlers were added to the group defines the
|
||||
priority.
|
||||
|
||||
|
@ -990,7 +991,7 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AbstractAsyncContextManager)
|
|||
conversation states may be overridden by the loaded data.
|
||||
|
||||
Args:
|
||||
handler (:class:`telegram.ext.Handler`): A Handler instance.
|
||||
handler (:class:`telegram.ext.BaseHandler`): A BaseHandler instance.
|
||||
group (:obj:`int`, optional): The group identifier. Default is ``0``.
|
||||
|
||||
"""
|
||||
|
@ -998,8 +999,8 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AbstractAsyncContextManager)
|
|||
# pylint: disable=import-outside-toplevel
|
||||
from telegram.ext._conversationhandler import ConversationHandler
|
||||
|
||||
if not isinstance(handler, Handler):
|
||||
raise TypeError(f"handler is not an instance of {Handler.__name__}")
|
||||
if not isinstance(handler, BaseHandler):
|
||||
raise TypeError(f"handler is not an instance of {BaseHandler.__name__}")
|
||||
if not isinstance(group, int):
|
||||
raise TypeError("group is not int")
|
||||
if isinstance(handler, ConversationHandler) and handler.persistent and handler.name:
|
||||
|
@ -1026,7 +1027,8 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AbstractAsyncContextManager)
|
|||
def add_handlers(
|
||||
self,
|
||||
handlers: Union[
|
||||
Union[List[Handler], Tuple[Handler]], Dict[int, Union[List[Handler], Tuple[Handler]]]
|
||||
Union[List[BaseHandler], Tuple[BaseHandler]],
|
||||
Dict[int, Union[List[BaseHandler], Tuple[BaseHandler]]],
|
||||
],
|
||||
group: DVInput[int] = DefaultValue(0),
|
||||
) -> None:
|
||||
|
@ -1036,8 +1038,8 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AbstractAsyncContextManager)
|
|||
.. versionadded:: 20.0
|
||||
|
||||
Args:
|
||||
handlers (List[:class:`telegram.ext.Handler`] | \
|
||||
Dict[int, List[:class:`telegram.ext.Handler`]]): \
|
||||
handlers (List[:class:`telegram.ext.BaseHandler`] | \
|
||||
Dict[int, List[:class:`telegram.ext.BaseHandler`]]): \
|
||||
Specify a sequence of handlers *or* a dictionary where the keys are groups and
|
||||
values are handlers.
|
||||
group (:obj:`int`, optional): Specify which group the sequence of :paramref:`handlers`
|
||||
|
@ -1072,11 +1074,12 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AbstractAsyncContextManager)
|
|||
"dictionary where the keys are groups and values are sequences of handlers."
|
||||
)
|
||||
|
||||
def remove_handler(self, handler: Handler, group: int = DEFAULT_GROUP) -> None:
|
||||
def remove_handler(self, handler: BaseHandler, group: int = DEFAULT_GROUP) -> None:
|
||||
"""Remove a handler from the specified group.
|
||||
|
||||
Args:
|
||||
handler (:class:`telegram.ext.Handler`): A :class:`telegram.ext.Handler` instance.
|
||||
handler (:class:`telegram.ext.BaseHandler`): A :class:`telegram.ext.BaseHandler`
|
||||
instance.
|
||||
group (:obj:`object`, optional): The group identifier. Default is ``0``.
|
||||
|
||||
"""
|
||||
|
|
|
@ -50,7 +50,7 @@ _STORING_DATA_WIKI = (
|
|||
|
||||
class CallbackContext(Generic[BT, UD, CD, BD]):
|
||||
"""
|
||||
This is a context object passed to the callback called by :class:`telegram.ext.Handler`
|
||||
This is a context object passed to the callback called by :class:`telegram.ext.BaseHandler`
|
||||
or by the :class:`telegram.ext.Application` in an error handler added by
|
||||
:attr:`telegram.ext.Application.add_error_handler` or to the callback of a
|
||||
:class:`telegram.ext.Job`.
|
||||
|
@ -65,7 +65,7 @@ class CallbackContext(Generic[BT, UD, CD, BD]):
|
|||
so make sure to use a fairly unique name for the attributes.
|
||||
|
||||
Warning:
|
||||
Do not combine custom attributes with :paramref:`telegram.ext.Handler.block` set to
|
||||
Do not combine custom attributes with :paramref:`telegram.ext.BaseHandler.block` set to
|
||||
:obj:`False` or :attr:`telegram.ext.Application.concurrent_updates` set to
|
||||
:obj:`True`. Due to how those work, it will almost certainly execute the callbacks for an
|
||||
update out of order, and the attributes that you think you added will not be present.
|
||||
|
@ -84,7 +84,7 @@ class CallbackContext(Generic[BT, UD, CD, BD]):
|
|||
Attributes:
|
||||
coroutine (:term:`coroutine function`): Optional. Only present in error handlers if the
|
||||
error was caused by a coroutine run with :meth:`Application.create_task` or a handler
|
||||
callback with :attr:`block=False <Handler.block>`.
|
||||
callback with :attr:`block=False <BaseHandler.block>`.
|
||||
matches (List[:meth:`re.Match <re.Match.expand>`]): Optional. If the associated update
|
||||
originated from a :class:`filters.Regex`, this will contain a list of match objects for
|
||||
every pattern where ``re.search(pattern, string)`` returned a match. Note that filters
|
||||
|
|
|
@ -24,7 +24,7 @@ from typing import TYPE_CHECKING, Callable, Match, Optional, Pattern, TypeVar, U
|
|||
from telegram import Update
|
||||
from telegram._utils.defaultvalue import DEFAULT_TRUE
|
||||
from telegram._utils.types import DVInput
|
||||
from telegram.ext._handler import Handler
|
||||
from telegram.ext._handler import BaseHandler
|
||||
from telegram.ext._utils.types import CCT, HandlerCallback
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -33,9 +33,9 @@ if TYPE_CHECKING:
|
|||
RT = TypeVar("RT")
|
||||
|
||||
|
||||
class CallbackQueryHandler(Handler[Update, CCT]):
|
||||
"""Handler class to handle Telegram :attr:`callback queries <telegram.Update.callback_query>`.
|
||||
Optionally based on a regex.
|
||||
class CallbackQueryHandler(BaseHandler[Update, CCT]):
|
||||
"""BaseHandler class to handle Telegram
|
||||
:attr:`callback queries <telegram.Update.callback_query>`. Optionally based on a regex.
|
||||
|
||||
Read the documentation of the :mod:`re` module for more information.
|
||||
|
||||
|
|
|
@ -20,12 +20,12 @@
|
|||
|
||||
|
||||
from telegram import Update
|
||||
from telegram.ext._handler import Handler
|
||||
from telegram.ext._handler import BaseHandler
|
||||
from telegram.ext._utils.types import CCT
|
||||
|
||||
|
||||
class ChatJoinRequestHandler(Handler[Update, CCT]):
|
||||
"""Handler class to handle Telegram updates that contain
|
||||
class ChatJoinRequestHandler(BaseHandler[Update, CCT]):
|
||||
"""BaseHandler class to handle Telegram updates that contain
|
||||
:attr:`telegram.Update.chat_join_request`.
|
||||
|
||||
Warning:
|
||||
|
|
|
@ -22,14 +22,14 @@ from typing import ClassVar, TypeVar
|
|||
from telegram import Update
|
||||
from telegram._utils.defaultvalue import DEFAULT_TRUE
|
||||
from telegram._utils.types import DVInput
|
||||
from telegram.ext._handler import Handler
|
||||
from telegram.ext._handler import BaseHandler
|
||||
from telegram.ext._utils.types import CCT, HandlerCallback
|
||||
|
||||
RT = TypeVar("RT")
|
||||
|
||||
|
||||
class ChatMemberHandler(Handler[Update, CCT]):
|
||||
"""Handler class to handle Telegram updates that contain a chat member update.
|
||||
class ChatMemberHandler(BaseHandler[Update, CCT]):
|
||||
"""BaseHandler class to handle Telegram updates that contain a chat member update.
|
||||
|
||||
.. versionadded:: 13.4
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ from typing import TYPE_CHECKING, Match, Optional, Pattern, TypeVar, Union, cast
|
|||
from telegram import Update
|
||||
from telegram._utils.defaultvalue import DEFAULT_TRUE
|
||||
from telegram._utils.types import DVInput
|
||||
from telegram.ext._handler import Handler
|
||||
from telegram.ext._handler import BaseHandler
|
||||
from telegram.ext._utils.types import CCT, HandlerCallback
|
||||
|
||||
RT = TypeVar("RT")
|
||||
|
@ -32,8 +32,8 @@ if TYPE_CHECKING:
|
|||
from telegram.ext import Application, CallbackContext
|
||||
|
||||
|
||||
class ChosenInlineResultHandler(Handler[Update, CCT]):
|
||||
"""Handler class to handle Telegram updates that contain
|
||||
class ChosenInlineResultHandler(BaseHandler[Update, CCT]):
|
||||
"""BaseHandler class to handle Telegram updates that contain
|
||||
:attr:`telegram.Update.chosen_inline_result`.
|
||||
|
||||
Warning:
|
||||
|
|
|
@ -24,7 +24,7 @@ from telegram import MessageEntity, Update
|
|||
from telegram._utils.defaultvalue import DEFAULT_TRUE
|
||||
from telegram._utils.types import SLT, DVInput
|
||||
from telegram.ext import filters as filters_module
|
||||
from telegram.ext._handler import Handler
|
||||
from telegram.ext._handler import BaseHandler
|
||||
from telegram.ext._utils.types import CCT, HandlerCallback
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -33,8 +33,8 @@ if TYPE_CHECKING:
|
|||
RT = TypeVar("RT")
|
||||
|
||||
|
||||
class CommandHandler(Handler[Update, CCT]):
|
||||
"""Handler class to handle Telegram commands.
|
||||
class CommandHandler(BaseHandler[Update, CCT]):
|
||||
"""BaseHandler class to handle Telegram commands.
|
||||
|
||||
Commands are Telegram messages that start with ``/``, optionally followed by an ``@`` and the
|
||||
bot's name and/or some additional text. The handler will add a :obj:`list` to the
|
||||
|
@ -164,7 +164,7 @@ class CommandHandler(Handler[Update, CCT]):
|
|||
|
||||
|
||||
class PrefixHandler(CommandHandler):
|
||||
"""Handler class to handle custom prefix commands.
|
||||
"""BaseHandler class to handle custom prefix commands.
|
||||
|
||||
This is an intermediate handler between :class:`MessageHandler` and :class:`CommandHandler`.
|
||||
It supports configurable commands with the same options as :class:`CommandHandler`. It will
|
||||
|
|
|
@ -46,7 +46,7 @@ from telegram.ext._callbackcontext import CallbackContext
|
|||
from telegram.ext._callbackqueryhandler import CallbackQueryHandler
|
||||
from telegram.ext._choseninlineresulthandler import ChosenInlineResultHandler
|
||||
from telegram.ext._extbot import ExtBot
|
||||
from telegram.ext._handler import Handler
|
||||
from telegram.ext._handler import BaseHandler
|
||||
from telegram.ext._inlinequeryhandler import InlineQueryHandler
|
||||
from telegram.ext._stringcommandhandler import StringCommandHandler
|
||||
from telegram.ext._stringregexhandler import StringRegexHandler
|
||||
|
@ -56,7 +56,7 @@ from telegram.ext._utils.types import CCT, ConversationDict, ConversationKey
|
|||
|
||||
if TYPE_CHECKING:
|
||||
from telegram.ext import Application, Job, JobQueue
|
||||
_CheckUpdateType = Tuple[object, ConversationKey, Handler, object]
|
||||
_CheckUpdateType = Tuple[object, ConversationKey, BaseHandler, object]
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -117,7 +117,7 @@ class PendingState:
|
|||
return res
|
||||
|
||||
|
||||
class ConversationHandler(Handler[Update, CCT]):
|
||||
class ConversationHandler(BaseHandler[Update, CCT]):
|
||||
"""
|
||||
A handler to hold a conversation with a single or multiple users through Telegram updates by
|
||||
managing three collections of other handlers.
|
||||
|
@ -186,16 +186,17 @@ class ConversationHandler(Handler[Update, CCT]):
|
|||
/examples#examples
|
||||
|
||||
Args:
|
||||
entry_points (List[:class:`telegram.ext.Handler`]): A list of :obj:`Handler` objects that
|
||||
entry_points (List[:class:`telegram.ext.BaseHandler`]): A list of :obj:`BaseHandler`
|
||||
objects that
|
||||
can trigger the start of the conversation. The first handler whose :meth:`check_update`
|
||||
method returns :obj:`True` will be used. If all return :obj:`False`, the update is not
|
||||
handled.
|
||||
states (Dict[:obj:`object`, List[:class:`telegram.ext.Handler`]]): A :obj:`dict` that
|
||||
states (Dict[:obj:`object`, List[:class:`telegram.ext.BaseHandler`]]): A :obj:`dict` that
|
||||
defines the different states of conversation a user can be in and one or more
|
||||
associated :obj:`Handler` objects that should be used in that state. The first handler
|
||||
whose :meth:`check_update` method returns :obj:`True` will be used.
|
||||
fallbacks (List[:class:`telegram.ext.Handler`]): A list of handlers that might be used if
|
||||
the user is in a conversation, but every handler for their current state returned
|
||||
associated :obj:`BaseHandler` objects that should be used in that state. The first
|
||||
handler whose :meth:`check_update` method returns :obj:`True` will be used.
|
||||
fallbacks (List[:class:`telegram.ext.BaseHandler`]): A list of handlers that might be used
|
||||
if the user is in a conversation, but every handler for their current state returned
|
||||
:obj:`False` on :meth:`check_update`. The first handler which :meth:`check_update`
|
||||
method returns :obj:`True` will be used. If all return :obj:`False`, the update is not
|
||||
handled.
|
||||
|
@ -231,11 +232,11 @@ class ConversationHandler(Handler[Update, CCT]):
|
|||
used to instruct a child conversation handler to transition into a mapped state on
|
||||
its parent conversation handler in place of a specified nested state.
|
||||
block (:obj:`bool`, optional): Pass :obj:`False` or :obj:`True` to set a default value for
|
||||
the :attr:`Handler.block` setting of all handlers (in :attr:`entry_points`,
|
||||
the :attr:`BaseHandler.block` setting of all handlers (in :attr:`entry_points`,
|
||||
:attr:`states` and :attr:`fallbacks`). The resolution order for checking if a handler
|
||||
should be run non-blocking is:
|
||||
|
||||
1. :attr:`telegram.ext.Handler.block` (if set)
|
||||
1. :attr:`telegram.ext.BaseHandler.block` (if set)
|
||||
2. the value passed to this parameter (if any)
|
||||
3. :attr:`telegram.ext.Defaults.block` (if defaults are used)
|
||||
|
||||
|
@ -283,9 +284,9 @@ class ConversationHandler(Handler[Update, CCT]):
|
|||
# pylint: disable=super-init-not-called
|
||||
def __init__(
|
||||
self,
|
||||
entry_points: List[Handler[Update, CCT]],
|
||||
states: Dict[object, List[Handler[Update, CCT]]],
|
||||
fallbacks: List[Handler[Update, CCT]],
|
||||
entry_points: List[BaseHandler[Update, CCT]],
|
||||
states: Dict[object, List[BaseHandler[Update, CCT]]],
|
||||
fallbacks: List[BaseHandler[Update, CCT]],
|
||||
allow_reentry: bool = False,
|
||||
per_chat: bool = True,
|
||||
per_user: bool = True,
|
||||
|
@ -343,7 +344,7 @@ class ConversationHandler(Handler[Update, CCT]):
|
|||
stacklevel=2,
|
||||
)
|
||||
|
||||
all_handlers: List[Handler] = []
|
||||
all_handlers: List[BaseHandler] = []
|
||||
all_handlers.extend(entry_points)
|
||||
all_handlers.extend(fallbacks)
|
||||
|
||||
|
@ -426,9 +427,9 @@ class ConversationHandler(Handler[Update, CCT]):
|
|||
)
|
||||
|
||||
@property
|
||||
def entry_points(self) -> List[Handler]:
|
||||
"""List[:class:`telegram.ext.Handler`]: A list of :obj:`Handler` objects that can trigger
|
||||
the start of the conversation.
|
||||
def entry_points(self) -> List[BaseHandler]:
|
||||
"""List[:class:`telegram.ext.BaseHandler`]: A list of :obj:`BaseHandler` objects that can
|
||||
trigger the start of the conversation.
|
||||
"""
|
||||
return self._entry_points
|
||||
|
||||
|
@ -439,10 +440,10 @@ class ConversationHandler(Handler[Update, CCT]):
|
|||
)
|
||||
|
||||
@property
|
||||
def states(self) -> Dict[object, List[Handler]]:
|
||||
"""Dict[:obj:`object`, List[:class:`telegram.ext.Handler`]]: A :obj:`dict` that
|
||||
def states(self) -> Dict[object, List[BaseHandler]]:
|
||||
"""Dict[:obj:`object`, List[:class:`telegram.ext.BaseHandler`]]: A :obj:`dict` that
|
||||
defines the different states of conversation a user can be in and one or more
|
||||
associated :obj:`Handler` objects that should be used in that state.
|
||||
associated :obj:`BaseHandler` objects that should be used in that state.
|
||||
"""
|
||||
return self._states
|
||||
|
||||
|
@ -451,8 +452,8 @@ class ConversationHandler(Handler[Update, CCT]):
|
|||
raise AttributeError("You can not assign a new value to states after initialization.")
|
||||
|
||||
@property
|
||||
def fallbacks(self) -> List[Handler]:
|
||||
"""List[:class:`telegram.ext.Handler`]: A list of handlers that might be used if
|
||||
def fallbacks(self) -> List[BaseHandler]:
|
||||
"""List[:class:`telegram.ext.BaseHandler`]: A list of handlers that might be used if
|
||||
the user is in a conversation, but every handler for their current state returned
|
||||
:obj:`False` on :meth:`check_update`.
|
||||
"""
|
||||
|
@ -723,7 +724,7 @@ class ConversationHandler(Handler[Update, CCT]):
|
|||
|
||||
_logger.debug("Selecting conversation %s with state %s", str(key), str(state))
|
||||
|
||||
handler: Optional[Handler] = None
|
||||
handler: Optional[BaseHandler] = None
|
||||
|
||||
# Search entry points for a match
|
||||
if state is None or self.allow_reentry:
|
||||
|
@ -765,7 +766,7 @@ class ConversationHandler(Handler[Update, CCT]):
|
|||
check_result: _CheckUpdateType,
|
||||
context: CallbackContext,
|
||||
) -> Optional[object]:
|
||||
"""Send the update to the callback for the current state and Handler
|
||||
"""Send the update to the callback for the current state and BaseHandler
|
||||
|
||||
Args:
|
||||
check_result: The result from :meth:`check_update`. For this handler it's a tuple of
|
||||
|
@ -872,7 +873,7 @@ class ConversationHandler(Handler[Update, CCT]):
|
|||
elif new_state is not None:
|
||||
if new_state not in self.states:
|
||||
warn(
|
||||
f"Handler returned state {new_state} which is unknown to the "
|
||||
f"BaseHandler returned state {new_state} which is unknown to the "
|
||||
f"ConversationHandler{' ' + self.name if self.name is not None else ''}.",
|
||||
stacklevel=2,
|
||||
)
|
||||
|
@ -880,7 +881,7 @@ class ConversationHandler(Handler[Update, CCT]):
|
|||
|
||||
async def _trigger_timeout(self, context: CallbackContext) -> None:
|
||||
"""This is run whenever a conversation has timed out. Also makes sure that all handlers
|
||||
which are in the :attr:`TIMEOUT` state and whose :meth:`Handler.check_update` returns
|
||||
which are in the :attr:`TIMEOUT` state and whose :meth:`BaseHandler.check_update` returns
|
||||
:obj:`True` is handled.
|
||||
"""
|
||||
job = cast("Job", context.job)
|
||||
|
|
|
@ -47,7 +47,8 @@ class Defaults:
|
|||
appearing throughout PTB, i.e. if a timezone naive date(time) object is passed
|
||||
somewhere, it will be assumed to be in :paramref:`tzinfo`. Must be a timezone provided
|
||||
by the ``pytz`` module. Defaults to UTC.
|
||||
block (:obj:`bool`, optional): Default setting for the :paramref:`Handler.block` parameter
|
||||
block (:obj:`bool`, optional): Default setting for the :paramref:`BaseHandler.block`
|
||||
parameter
|
||||
of handlers and error handlers registered through :meth:`Application.add_handler` and
|
||||
:meth:`Application.add_error_handler`. Defaults to :obj:`True`.
|
||||
protect_content (:obj:`bool`, optional): Protects the contents of the sent message from
|
||||
|
@ -194,8 +195,8 @@ class Defaults:
|
|||
|
||||
@property
|
||||
def block(self) -> bool:
|
||||
""":obj:`bool`: Optional. Default setting for the :paramref:`Handler.block` parameter of
|
||||
handlers and error handlers registered through :meth:`Application.add_handler` and
|
||||
""":obj:`bool`: Optional. Default setting for the :paramref:`BaseHandler.block` parameter
|
||||
of handlers and error handlers registered through :meth:`Application.add_handler` and
|
||||
:meth:`Application.add_error_handler`.
|
||||
"""
|
||||
return self._block
|
||||
|
|
|
@ -31,7 +31,7 @@ RT = TypeVar("RT")
|
|||
UT = TypeVar("UT")
|
||||
|
||||
|
||||
class Handler(Generic[UT, CCT], ABC):
|
||||
class BaseHandler(Generic[UT, CCT], ABC):
|
||||
"""The base class for all update handlers. Create custom handlers by inheriting from it.
|
||||
|
||||
Warning:
|
||||
|
@ -55,7 +55,9 @@ class Handler(Generic[UT, CCT], ABC):
|
|||
this handler fits the definition of the :class:`~Application`.
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
The attribute ``run_async`` is now :paramref:`block`.
|
||||
|
||||
* The attribute ``run_async`` is now :paramref:`block`.
|
||||
* This class was previously named ``Handler``.
|
||||
|
||||
Args:
|
||||
callback (:term:`coroutine function`): The callback function for this handler. Will be
|
||||
|
|
|
@ -23,7 +23,7 @@ from typing import TYPE_CHECKING, List, Match, Optional, Pattern, TypeVar, Union
|
|||
from telegram import Update
|
||||
from telegram._utils.defaultvalue import DEFAULT_TRUE
|
||||
from telegram._utils.types import DVInput
|
||||
from telegram.ext._handler import Handler
|
||||
from telegram.ext._handler import BaseHandler
|
||||
from telegram.ext._utils.types import CCT, HandlerCallback
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -32,9 +32,10 @@ if TYPE_CHECKING:
|
|||
RT = TypeVar("RT")
|
||||
|
||||
|
||||
class InlineQueryHandler(Handler[Update, CCT]):
|
||||
class InlineQueryHandler(BaseHandler[Update, CCT]):
|
||||
"""
|
||||
Handler class to handle Telegram updates that contain a :attr:`telegram.Update.inline_query`.
|
||||
BaseHandler class to handle Telegram updates that contain a
|
||||
:attr:`telegram.Update.inline_query`.
|
||||
Optionally based on a regex. Read the documentation of the :mod:`re` module for more
|
||||
information.
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ from telegram import Update
|
|||
from telegram._utils.defaultvalue import DEFAULT_TRUE
|
||||
from telegram._utils.types import DVInput
|
||||
from telegram.ext import filters as filters_module
|
||||
from telegram.ext._handler import Handler
|
||||
from telegram.ext._handler import BaseHandler
|
||||
from telegram.ext._utils.types import CCT, HandlerCallback
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -32,8 +32,9 @@ if TYPE_CHECKING:
|
|||
RT = TypeVar("RT")
|
||||
|
||||
|
||||
class MessageHandler(Handler[Update, CCT]):
|
||||
"""Handler class to handle Telegram messages. They might contain text, media or status updates.
|
||||
class MessageHandler(BaseHandler[Update, CCT]):
|
||||
"""BaseHandler class to handle Telegram messages. They might contain text, media or status
|
||||
updates.
|
||||
|
||||
Warning:
|
||||
When setting :paramref:`block` to :obj:`False`, you cannot rely on adding custom
|
||||
|
|
|
@ -20,12 +20,12 @@
|
|||
|
||||
|
||||
from telegram import Update
|
||||
from telegram.ext._handler import Handler
|
||||
from telegram.ext._handler import BaseHandler
|
||||
from telegram.ext._utils.types import CCT
|
||||
|
||||
|
||||
class PollAnswerHandler(Handler[Update, CCT]):
|
||||
"""Handler class to handle Telegram updates that contain a
|
||||
class PollAnswerHandler(BaseHandler[Update, CCT]):
|
||||
"""BaseHandler class to handle Telegram updates that contain a
|
||||
:attr:`poll answer <telegram.Update.poll_answer>`.
|
||||
|
||||
Warning:
|
||||
|
|
|
@ -20,12 +20,13 @@
|
|||
|
||||
|
||||
from telegram import Update
|
||||
from telegram.ext._handler import Handler
|
||||
from telegram.ext._handler import BaseHandler
|
||||
from telegram.ext._utils.types import CCT
|
||||
|
||||
|
||||
class PollHandler(Handler[Update, CCT]):
|
||||
"""Handler class to handle Telegram updates that contain a :attr:`poll <telegram.Update.poll>`.
|
||||
class PollHandler(BaseHandler[Update, CCT]):
|
||||
"""BaseHandler class to handle Telegram updates that contain a
|
||||
:attr:`poll <telegram.Update.poll>`.
|
||||
|
||||
Warning:
|
||||
When setting :paramref:`block` to :obj:`False`, you cannot rely on adding custom
|
||||
|
|
|
@ -20,12 +20,12 @@
|
|||
|
||||
|
||||
from telegram import Update
|
||||
from telegram.ext._handler import Handler
|
||||
from telegram.ext._handler import BaseHandler
|
||||
from telegram.ext._utils.types import CCT
|
||||
|
||||
|
||||
class PreCheckoutQueryHandler(Handler[Update, CCT]):
|
||||
"""Handler class to handle Telegram :attr:`telegram.Update.pre_checkout_query`.
|
||||
class PreCheckoutQueryHandler(BaseHandler[Update, CCT]):
|
||||
"""BaseHandler class to handle Telegram :attr:`telegram.Update.pre_checkout_query`.
|
||||
|
||||
Warning:
|
||||
When setting :paramref:`block` to :obj:`False`, you cannot rely on adding custom
|
||||
|
|
|
@ -20,12 +20,12 @@
|
|||
|
||||
|
||||
from telegram import Update
|
||||
from telegram.ext._handler import Handler
|
||||
from telegram.ext._handler import BaseHandler
|
||||
from telegram.ext._utils.types import CCT
|
||||
|
||||
|
||||
class ShippingQueryHandler(Handler[Update, CCT]):
|
||||
"""Handler class to handle Telegram :attr:`telegram.Update.shipping_query`.
|
||||
class ShippingQueryHandler(BaseHandler[Update, CCT]):
|
||||
"""BaseHandler class to handle Telegram :attr:`telegram.Update.shipping_query`.
|
||||
|
||||
Warning:
|
||||
When setting :paramref:`block` to :obj:`False`, you cannot rely on adding custom
|
||||
|
|
|
@ -22,16 +22,16 @@ from typing import TYPE_CHECKING, List, Optional
|
|||
|
||||
from telegram._utils.defaultvalue import DEFAULT_TRUE
|
||||
from telegram._utils.types import DVInput
|
||||
from telegram.ext._handler import Handler
|
||||
from telegram.ext._handler import BaseHandler
|
||||
from telegram.ext._utils.types import CCT, RT, HandlerCallback
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram.ext import Application
|
||||
|
||||
|
||||
class StringCommandHandler(Handler[str, CCT]):
|
||||
"""Handler class to handle string commands. Commands are string updates that start with ``/``.
|
||||
The handler will add a :obj:`list` to the
|
||||
class StringCommandHandler(BaseHandler[str, CCT]):
|
||||
"""BaseHandler class to handle string commands. Commands are string updates that start with
|
||||
``/``. The handler will add a :obj:`list` to the
|
||||
:class:`CallbackContext` named :attr:`CallbackContext.args`. It will contain a list of strings,
|
||||
which is the text following the command split on single whitespace characters.
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ from typing import TYPE_CHECKING, Match, Optional, Pattern, TypeVar, Union
|
|||
|
||||
from telegram._utils.defaultvalue import DEFAULT_TRUE
|
||||
from telegram._utils.types import DVInput
|
||||
from telegram.ext._handler import Handler
|
||||
from telegram.ext._handler import BaseHandler
|
||||
from telegram.ext._utils.types import CCT, HandlerCallback
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -32,8 +32,8 @@ if TYPE_CHECKING:
|
|||
RT = TypeVar("RT")
|
||||
|
||||
|
||||
class StringRegexHandler(Handler[str, CCT]):
|
||||
"""Handler class to handle string updates based on a regex which checks the update content.
|
||||
class StringRegexHandler(BaseHandler[str, CCT]):
|
||||
"""BaseHandler class to handle string updates based on a regex which checks the update content.
|
||||
|
||||
Read the documentation of the :mod:`re` module for more information. The :func:`re.match`
|
||||
function is used to determine if an update should be handled by this handler.
|
||||
|
|
|
@ -22,15 +22,15 @@ from typing import Type, TypeVar
|
|||
|
||||
from telegram._utils.defaultvalue import DEFAULT_TRUE
|
||||
from telegram._utils.types import DVInput
|
||||
from telegram.ext._handler import Handler
|
||||
from telegram.ext._handler import BaseHandler
|
||||
from telegram.ext._utils.types import CCT, HandlerCallback
|
||||
|
||||
RT = TypeVar("RT")
|
||||
UT = TypeVar("UT")
|
||||
|
||||
|
||||
class TypeHandler(Handler[UT, CCT]):
|
||||
"""Handler class to handle updates of custom types.
|
||||
class TypeHandler(BaseHandler[UT, CCT]):
|
||||
"""BaseHandler class to handle updates of custom types.
|
||||
|
||||
Warning:
|
||||
When setting :paramref:`block` to :obj:`False`, you cannot rely on adding custom
|
||||
|
|
|
@ -98,7 +98,7 @@ class WebhookAppClass(tornado.web.Application):
|
|||
|
||||
# pylint: disable=abstract-method
|
||||
class TelegramHandler(tornado.web.RequestHandler):
|
||||
"""Handler that processes incoming requests from Telegram"""
|
||||
"""BaseHandler that processes incoming requests from Telegram"""
|
||||
|
||||
__slots__ = ("bot", "update_queue", "_logger")
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ from telegram.ext import (
|
|||
CommandHandler,
|
||||
ContextTypes,
|
||||
Defaults,
|
||||
Handler,
|
||||
BaseHandler,
|
||||
JobQueue,
|
||||
MessageHandler,
|
||||
PicklePersistence,
|
||||
|
@ -587,7 +587,7 @@ class TestApplication:
|
|||
await app.stop()
|
||||
|
||||
async def test_check_update(self, app):
|
||||
class TestHandler(Handler):
|
||||
class TestHandler(BaseHandler):
|
||||
def check_update(_, update: object):
|
||||
self.received = object()
|
||||
|
||||
|
@ -862,7 +862,7 @@ class TestApplication:
|
|||
[(True, True), (None, False), (False, False), ({}, True), ("", True), ("check", True)],
|
||||
)
|
||||
async def test_check_update_handling(self, app, check, expected):
|
||||
class MyHandler(Handler):
|
||||
class MyHandler(BaseHandler):
|
||||
def check_update(self, update: object):
|
||||
return check
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ from telegram.ext import (
|
|||
BasePersistence,
|
||||
CallbackContext,
|
||||
ConversationHandler,
|
||||
Handler,
|
||||
BaseHandler,
|
||||
MessageHandler,
|
||||
PersistenceInput,
|
||||
filters,
|
||||
|
@ -247,7 +247,7 @@ def build_papp(
|
|||
)
|
||||
|
||||
|
||||
def build_conversation_handler(name: str, persistent: bool = True) -> Handler:
|
||||
def build_conversation_handler(name: str, persistent: bool = True) -> BaseHandler:
|
||||
return TrackingConversationHandler(name=name, persistent=persistent)
|
||||
|
||||
|
||||
|
|
|
@ -670,7 +670,7 @@ class TestConversationHandler:
|
|||
raise exc
|
||||
assert len(recwarn) == 1
|
||||
assert str(recwarn[0].message) == (
|
||||
"Handler returned state 69 which is unknown to the ConversationHandler xyz."
|
||||
"BaseHandler returned state 69 which is unknown to the ConversationHandler xyz."
|
||||
)
|
||||
|
||||
async def test_conversation_handler_per_chat(self, app, bot, user1, user2):
|
||||
|
|
|
@ -17,12 +17,12 @@
|
|||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
from telegram.ext._handler import Handler
|
||||
from telegram.ext._handler import BaseHandler
|
||||
|
||||
|
||||
class TestHandler:
|
||||
def test_slot_behaviour(self, mro_slots):
|
||||
class SubclassHandler(Handler):
|
||||
class SubclassHandler(BaseHandler):
|
||||
__slots__ = ()
|
||||
|
||||
def __init__(self):
|
||||
|
|
Loading…
Reference in a new issue