mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 10:11:52 +00:00
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.
This commit is contained in:
parent
e6e2601d4b
commit
0cf5afeb99
2 changed files with 54 additions and 0 deletions
|
|
@ -297,6 +297,36 @@ class Bot:
|
||||||
self.__token = token
|
self.__token = token
|
||||||
self._me: Optional[User] = None
|
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
|
@property
|
||||||
def token(self) -> str:
|
def token(self) -> str:
|
||||||
return self.__token
|
return self.__token
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,30 @@ class TestBot:
|
||||||
):
|
):
|
||||||
bot = Bot(token="42:Test", parse_mode="HTML")
|
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):
|
def test_hashable(self):
|
||||||
bot = Bot("42:TEST")
|
bot = Bot("42:TEST")
|
||||||
assert hash(bot) == hash("42:TEST")
|
assert hash(bot) == hash("42:TEST")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue