Skip to content

Commit

Permalink
Move Handler Files to _handlers Subdirectory (#4064)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmolinari committed Jan 15, 2024
1 parent ebf7f3b commit f452c13
Show file tree
Hide file tree
Showing 25 changed files with 55 additions and 50 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ The following wonderful people contributed directly or indirectly to this projec
- `Loo Zheng Yuan <https://github.com/loozhengyuan>`_
- `LRezende <https://github.com/lrezende>`_
- `Luca Bellanti <https://github.com/Trifase>`_
- `Lucas Molinari <https://github.com/lucasmolinari>`_
- `macrojames <https://github.com/macrojames>`_
- `Matheus Lemos <https://github.com/mlemosf>`_
- `Michael Dix <https://github.com/Eisberge>`_
Expand Down
34 changes: 17 additions & 17 deletions telegram/ext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,32 @@
from ._aioratelimiter import AIORateLimiter
from ._application import Application, ApplicationHandlerStop
from ._applicationbuilder import ApplicationBuilder
from ._basehandler import BaseHandler
from ._basepersistence import BasePersistence, PersistenceInput
from ._baseratelimiter import BaseRateLimiter
from ._baseupdateprocessor import BaseUpdateProcessor, SimpleUpdateProcessor
from ._callbackcontext import CallbackContext
from ._callbackdatacache import CallbackDataCache, InvalidCallbackData
from ._callbackqueryhandler import CallbackQueryHandler
from ._chatjoinrequesthandler import ChatJoinRequestHandler
from ._chatmemberhandler import ChatMemberHandler
from ._choseninlineresulthandler import ChosenInlineResultHandler
from ._commandhandler import CommandHandler
from ._contexttypes import ContextTypes
from ._conversationhandler import ConversationHandler
from ._defaults import Defaults
from ._dictpersistence import DictPersistence
from ._extbot import ExtBot
from ._inlinequeryhandler import InlineQueryHandler
from ._handlers.basehandler import BaseHandler
from ._handlers.callbackqueryhandler import CallbackQueryHandler
from ._handlers.chatjoinrequesthandler import ChatJoinRequestHandler
from ._handlers.chatmemberhandler import ChatMemberHandler
from ._handlers.choseninlineresulthandler import ChosenInlineResultHandler
from ._handlers.commandhandler import CommandHandler
from ._handlers.conversationhandler import ConversationHandler
from ._handlers.inlinequeryhandler import InlineQueryHandler
from ._handlers.messagehandler import MessageHandler
from ._handlers.pollanswerhandler import PollAnswerHandler
from ._handlers.pollhandler import PollHandler
from ._handlers.precheckoutqueryhandler import PreCheckoutQueryHandler
from ._handlers.prefixhandler import PrefixHandler
from ._handlers.shippingqueryhandler import ShippingQueryHandler
from ._handlers.stringcommandhandler import StringCommandHandler
from ._handlers.stringregexhandler import StringRegexHandler
from ._handlers.typehandler import TypeHandler
from ._jobqueue import Job, JobQueue
from ._messagehandler import MessageHandler
from ._picklepersistence import PicklePersistence
from ._pollanswerhandler import PollAnswerHandler
from ._pollhandler import PollHandler
from ._precheckoutqueryhandler import PreCheckoutQueryHandler
from ._prefixhandler import PrefixHandler
from ._shippingqueryhandler import ShippingQueryHandler
from ._stringcommandhandler import StringCommandHandler
from ._stringregexhandler import StringRegexHandler
from ._typehandler import TypeHandler
from ._updater import Updater
8 changes: 4 additions & 4 deletions telegram/ext/_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@
from telegram._utils.types import SCT, DVType, ODVInput
from telegram._utils.warnings import warn
from telegram.error import TelegramError
from telegram.ext._basehandler import BaseHandler
from telegram.ext._basepersistence import BasePersistence
from telegram.ext._contexttypes import ContextTypes
from telegram.ext._extbot import ExtBot
from telegram.ext._handlers.basehandler import BaseHandler
from telegram.ext._updater import Updater
from telegram.ext._utils.stack import was_called_by
from telegram.ext._utils.trackingdict import TrackingDict
Expand Down Expand Up @@ -494,7 +494,7 @@ async def initialize(self) -> None:

# Unfortunately due to circular imports this has to be here
# pylint: disable=import-outside-toplevel
from telegram.ext._conversationhandler import ConversationHandler
from telegram.ext._handlers.conversationhandler import ConversationHandler

# Initialize the persistent conversation handlers with the stored states
for handler in itertools.chain.from_iterable(self.handlers.values()):
Expand Down Expand Up @@ -1304,7 +1304,7 @@ def add_handler(self, handler: BaseHandler[Any, CCT], group: int = DEFAULT_GROUP
"""
# Unfortunately due to circular imports this has to be here
# pylint: disable=import-outside-toplevel
from telegram.ext._conversationhandler import ConversationHandler
from telegram.ext._handlers.conversationhandler import ConversationHandler

if not isinstance(handler, BaseHandler):
raise TypeError(f"handler is not an instance of {BaseHandler.__name__}")
Expand Down Expand Up @@ -1650,7 +1650,7 @@ async def __update_persistence(self) -> None:

# Unfortunately due to circular imports this has to be here
# pylint: disable=import-outside-toplevel
from telegram.ext._conversationhandler import PendingState
from telegram.ext._handlers.conversationhandler import PendingState

for name, (key, new_state) in itertools.chain.from_iterable(
zip(itertools.repeat(name), states_dict.pop_accessed_write_items())
Expand Down
Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from telegram import Update
from telegram._utils.defaultvalue import DEFAULT_TRUE
from telegram._utils.types import DVType
from telegram.ext._basehandler import BaseHandler
from telegram.ext._handlers.basehandler import BaseHandler
from telegram.ext._utils.types import CCT, HandlerCallback

if TYPE_CHECKING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from telegram import Update
from telegram._utils.defaultvalue import DEFAULT_TRUE
from telegram._utils.types import RT, SCT, DVType
from telegram.ext._basehandler import BaseHandler
from telegram.ext._handlers.basehandler import BaseHandler
from telegram.ext._utils.types import CCT, HandlerCallback


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from telegram import Update
from telegram._utils.defaultvalue import DEFAULT_TRUE
from telegram._utils.types import DVType
from telegram.ext._basehandler import BaseHandler
from telegram.ext._handlers.basehandler import BaseHandler
from telegram.ext._utils.types import CCT, HandlerCallback

RT = TypeVar("RT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from telegram import Update
from telegram._utils.defaultvalue import DEFAULT_TRUE
from telegram._utils.types import DVType
from telegram.ext._basehandler import BaseHandler
from telegram.ext._handlers.basehandler import BaseHandler
from telegram.ext._utils.types import CCT, HandlerCallback

RT = TypeVar("RT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from telegram._utils.defaultvalue import DEFAULT_TRUE
from telegram._utils.types import SCT, DVType
from telegram.ext import filters as filters_module
from telegram.ext._basehandler import BaseHandler
from telegram.ext._handlers.basehandler import BaseHandler
from telegram.ext._utils.types import CCT, FilterDataDict, HandlerCallback

if TYPE_CHECKING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
from telegram._utils.types import DVType
from telegram._utils.warnings import warn
from telegram.ext._application import ApplicationHandlerStop
from telegram.ext._basehandler import BaseHandler
from telegram.ext._callbackqueryhandler import CallbackQueryHandler
from telegram.ext._choseninlineresulthandler import ChosenInlineResultHandler
from telegram.ext._extbot import ExtBot
from telegram.ext._inlinequeryhandler import InlineQueryHandler
from telegram.ext._stringcommandhandler import StringCommandHandler
from telegram.ext._stringregexhandler import StringRegexHandler
from telegram.ext._typehandler import TypeHandler
from telegram.ext._handlers.basehandler import BaseHandler
from telegram.ext._handlers.callbackqueryhandler import CallbackQueryHandler
from telegram.ext._handlers.choseninlineresulthandler import ChosenInlineResultHandler
from telegram.ext._handlers.inlinequeryhandler import InlineQueryHandler
from telegram.ext._handlers.stringcommandhandler import StringCommandHandler
from telegram.ext._handlers.stringregexhandler import StringRegexHandler
from telegram.ext._handlers.typehandler import TypeHandler
from telegram.ext._utils.trackingdict import TrackingDict
from telegram.ext._utils.types import CCT, ConversationDict, ConversationKey

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from telegram import Update
from telegram._utils.defaultvalue import DEFAULT_TRUE
from telegram._utils.types import DVType
from telegram.ext._basehandler import BaseHandler
from telegram.ext._handlers.basehandler import BaseHandler
from telegram.ext._utils.types import CCT, HandlerCallback

if TYPE_CHECKING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from telegram._utils.defaultvalue import DEFAULT_TRUE
from telegram._utils.types import DVType
from telegram.ext import filters as filters_module
from telegram.ext._basehandler import BaseHandler
from telegram.ext._handlers.basehandler import BaseHandler
from telegram.ext._utils.types import CCT, HandlerCallback

if TYPE_CHECKING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


from telegram import Update
from telegram.ext._basehandler import BaseHandler
from telegram.ext._handlers.basehandler import BaseHandler
from telegram.ext._utils.types import CCT


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


from telegram import Update
from telegram.ext._basehandler import BaseHandler
from telegram.ext._handlers.basehandler import BaseHandler
from telegram.ext._utils.types import CCT


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from telegram import Update
from telegram._utils.defaultvalue import DEFAULT_TRUE
from telegram._utils.types import DVType
from telegram.ext._basehandler import BaseHandler
from telegram.ext._handlers.basehandler import BaseHandler
from telegram.ext._utils.types import CCT, HandlerCallback

RT = TypeVar("RT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from telegram._utils.defaultvalue import DEFAULT_TRUE
from telegram._utils.types import SCT, DVType
from telegram.ext import filters as filters_module
from telegram.ext._basehandler import BaseHandler
from telegram.ext._handlers.basehandler import BaseHandler
from telegram.ext._utils.types import CCT, HandlerCallback

if TYPE_CHECKING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


from telegram import Update
from telegram.ext._basehandler import BaseHandler
from telegram.ext._handlers.basehandler import BaseHandler
from telegram.ext._utils.types import CCT


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from telegram._utils.defaultvalue import DEFAULT_TRUE
from telegram._utils.types import DVType
from telegram.ext._basehandler import BaseHandler
from telegram.ext._handlers.basehandler import BaseHandler
from telegram.ext._utils.types import CCT, RT, HandlerCallback

if TYPE_CHECKING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from telegram._utils.defaultvalue import DEFAULT_TRUE
from telegram._utils.types import DVType
from telegram.ext._basehandler import BaseHandler
from telegram.ext._handlers.basehandler import BaseHandler
from telegram.ext._utils.types import CCT, HandlerCallback

if TYPE_CHECKING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from telegram._utils.defaultvalue import DEFAULT_TRUE
from telegram._utils.types import DVType
from telegram.ext._basehandler import BaseHandler
from telegram.ext._handlers.basehandler import BaseHandler
from telegram.ext._utils.types import CCT, HandlerCallback

RT = TypeVar("RT")
Expand Down
4 changes: 2 additions & 2 deletions tests/_files/test_inputmedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ async def test_send_media_group_photo(self, bot, chat_id, media_group):
assert len(messages) == 3
assert all(isinstance(mes, Message) for mes in messages)
assert all(mes.media_group_id == messages[0].media_group_id for mes in messages)
assert all(mes.caption == f"photo {idx+1}" for idx, mes in enumerate(messages))
assert all(mes.caption == f"photo {idx + 1}" for idx, mes in enumerate(messages))
assert all(
mes.caption_entities == (MessageEntity(MessageEntity.BOLD, 0, 5),) for mes in messages
)
Expand Down Expand Up @@ -742,7 +742,7 @@ async def test_send_media_group_all_args(self, bot, raw_bot, chat_id, media_grou
assert len(messages) == 3
assert all(isinstance(mes, Message) for mes in messages)
assert all(mes.media_group_id == messages[0].media_group_id for mes in messages)
assert all(mes.caption == f"photo {idx+1}" for idx, mes in enumerate(messages))
assert all(mes.caption == f"photo {idx + 1}" for idx, mes in enumerate(messages))
assert all(
mes.caption_entities == (MessageEntity(MessageEntity.BOLD, 0, 5),)
for mes in messages
Expand Down
2 changes: 1 addition & 1 deletion tests/ext/test_basehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +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/].

from telegram.ext._basehandler import BaseHandler
from telegram.ext import BaseHandler
from tests.auxil.slots import mro_slots


Expand Down
8 changes: 6 additions & 2 deletions tests/ext/test_conversationhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ async def callback(_, __):
assert recwarn[0].category is PTBUserWarning
assert (
Path(recwarn[0].filename)
== PROJECT_ROOT_PATH / "telegram" / "ext" / "_conversationhandler.py"
== PROJECT_ROOT_PATH / "telegram" / "ext" / "_handlers" / "conversationhandler.py"
), "wrong stacklevel!"
assert (
str(recwarn[0].message)
Expand Down Expand Up @@ -1105,7 +1105,11 @@ async def test_no_running_job_queue_warning(self, app, bot, user1, recwarn, jq):
assert warning.category is PTBUserWarning
assert (
Path(warning.filename)
== PROJECT_ROOT_PATH / "telegram" / "ext" / "_conversationhandler.py"
== PROJECT_ROOT_PATH
/ "telegram"
/ "ext"
/ "_handlers"
/ "conversationhandler.py"
), "wrong stacklevel!"
# now set app.job_queue back to it's original value

Expand Down
4 changes: 2 additions & 2 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3173,8 +3173,8 @@ async def test_set_and_get_my_commands(self, bot):
assert await bot.set_my_commands(commands)

for i, bc in enumerate(await bot.get_my_commands()):
assert bc.command == f"cmd{i+1}"
assert bc.description == f"descr{i+1}"
assert bc.command == f"cmd{i + 1}"
assert bc.description == f"descr{i + 1}"

async def test_get_set_delete_my_commands_with_scope(self, bot, super_group_id, chat_id):
group_cmds = [BotCommand("group_cmd", "visible to this supergroup only")]
Expand Down

0 comments on commit f452c13

Please sign in to comment.