From 0cf5afeb9937e3fe114180dffd2db4ca0e556b53 Mon Sep 17 00:00:00 2001 From: JRoot Junior Date: Fri, 16 Feb 2024 01:13:51 +0200 Subject: [PATCH] Add deprecation warnings to Bot properties Three properties of the Bot class - parse_mode, disable_web_page_preview, and protect_content - have been marked as deprecated with proper warning messages. The associated tests have also been added to confirm the working of these deprecation warnings. Users are advised to use the updated alternatives specified in the warning messages. --- aiogram/client/bot.py | 30 ++++++++++++++++++++++++++ tests/test_api/test_client/test_bot.py | 24 +++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/aiogram/client/bot.py b/aiogram/client/bot.py index 06cae1c4..93faa6aa 100644 --- a/aiogram/client/bot.py +++ b/aiogram/client/bot.py @@ -297,6 +297,36 @@ class Bot: self.__token = token self._me: Optional[User] = None + @property + def parse_mode(self) -> Optional[str]: + warnings.warn( + "Accessing `parse_mode` from Bot instance is deprecated. This attribute will be removed in 3.5.0 version\n" + "Use `bot.default.parse_mode` instead.", + category=DeprecationWarning, + stacklevel=2, + ) + return self.default.parse_mode + + @property + def disable_web_page_preview(self) -> Optional[bool]: + warnings.warn( + "Accessing `disable_web_page_preview` from Bot instance is deprecated. This attribute will be removed in 3.5.0 version\n" + "Use `bot.default.link_preview_is_disabled` instead.", + category=DeprecationWarning, + stacklevel=2, + ) + return self.default.link_preview_is_disabled + + @property + def protect_content(self) -> Optional[bool]: + warnings.warn( + "Accessing `protect_content` from Bot instance is deprecated. This attribute will be removed in 3.5.0 version\n" + "Use `bot.default.protect_content` instead.", + category=DeprecationWarning, + stacklevel=2, + ) + return self.default.protect_content + @property def token(self) -> str: return self.__token diff --git a/tests/test_api/test_client/test_bot.py b/tests/test_api/test_client/test_bot.py index 901beac2..bdac9ed9 100644 --- a/tests/test_api/test_client/test_bot.py +++ b/tests/test_api/test_client/test_bot.py @@ -49,6 +49,30 @@ class TestBot: ): bot = Bot(token="42:Test", parse_mode="HTML") + def test_deprecated_parse_mode(self): + with check_deprecated( + max_version="3.5.0", + exception=AttributeError, + ): + bot = Bot(token="42:Test", parse_mode="HTML") + assert bot.parse_mode == "HTML" + + def test_disable_web_page_preview(self): + with check_deprecated( + max_version="3.5.0", + exception=TypeError, + ): + bot = Bot(token="42:Test", disable_web_page_preview=True) + assert bot.disable_web_page_preview is True + + def test_deprecated_protect_content(self): + with check_deprecated( + max_version="3.5.0", + exception=AttributeError, + ): + bot = Bot(token="42:Test", protect_content=True) + assert bot.protect_content is True + def test_hashable(self): bot = Bot("42:TEST") assert hash(bot) == hash("42:TEST")