Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix: InputPaidMedia default parse_mode insertation#4761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall 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
6 changes: 6 additions & 0 deletionschanges/unreleased/4761.mmsngFA6b4ccdEzEpFTZS3.toml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
bugfixes = "Fix Handling of ``Defaults`` for ``InputPaidMedia``"

[[pull_requests]]
uid = "4761"
author_uid = "ngrogolev"
closes_threads = ["4753"]
8 changes: 6 additions & 2 deletionstelegram/ext/_extbot.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -62,6 +62,7 @@
InlineKeyboardMarkup,
InlineQueryResultsButton,
InputMedia,
InputPaidMedia,
InputPollOption,
LinkPreviewOptions,
Location,
Expand DownExpand Up@@ -114,7 +115,6 @@
InputMediaDocument,
InputMediaPhoto,
InputMediaVideo,
InputPaidMedia,
InputSticker,
LabeledPrice,
MessageEntity,
Expand DownExpand Up@@ -466,7 +466,11 @@ def _insert_defaults(self, data: dict[str, object]) -> None:
with copied_val._unfrozen():
copied_val.parse_mode = self.defaults.parse_mode
data[key] = copied_val
elif key == "media" and isinstance(val, Sequence):
elif (
key == "media"
and isinstance(val, Sequence)
and not isinstance(val[0], InputPaidMedia)
):
# Copy objects as not to edit them in-place
copy_list = [copy(media) for media in val]
for media in copy_list:
Expand Down
13 changes: 10 additions & 3 deletionstests/auxil/bot_method_checks.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,7 @@
InlineQueryResultArticle,
InlineQueryResultCachedPhoto,
InputMediaPhoto,
InputPaidMediaPhoto,
InputTextMessageContent,
LinkPreviewOptions,
ReplyParameters,
Expand DownExpand Up@@ -285,8 +286,13 @@ def build_kwargs(
elif name in ["prices", "commands", "errors"]:
kws[name] = []
elif name == "media":
media = InputMediaPhoto("media", parse_mode=manually_passed_value)
if "list" in str(param.annotation).lower():
if "star_count" in signature.parameters:
media = InputPaidMediaPhoto("media")
else:
media = InputMediaPhoto("media", parse_mode=manually_passed_value)

param_annotation = str(param.annotation).lower()
if "sequence" in param_annotation or "list" in param_annotation:
kws[name] = [media]
else:
kws[name] = media
Expand DownExpand Up@@ -507,7 +513,8 @@ def check_input_media(m: dict):
)

media = data.pop("media", None)
if media:
paid_media = media and data.pop("star_count", None)
if media and not paid_media:
if isinstance(media, dict) and isinstance(media.get("type", None), InputMediaType):
check_input_media(media)
else:
Expand Down
2 changes: 1 addition & 1 deletiontests/test_bot.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -543,7 +543,7 @@ def test_api_kwargs_and_timeouts_present(self, bot_class, bot_method_name, bot_m
if bot_method_name.replace("_", "").lower() != "getupdates" and bot_class is ExtBot:
assert rate_arg in param_names, f"{bot_method} is missing the parameter `{rate_arg}`"

@bot_methods(ext_bot=False)
@bot_methods()
async def test_defaults_handling(
self,
bot_class,
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp