Skip to content

Commit 34dd172

Browse files
meybjHitaloM
authored andcommitted
fix: add BinaryIO type to thumb in input medias
1 parent 7cf0def commit 34dd172

9 files changed

Lines changed: 51 additions & 31 deletions

File tree

cherry-pick-pyro.sh

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ RUFF_TOML=$(cat <<EOF
1010
line-length = 99
1111
target-version = "py39"
1212
select = [
13+
"FURB", # refurb
1314
"I", # isort
14-
"E", # pycodestyle
15-
"W", # pycodestyle
15+
"E", # pycodestyle: error
16+
"W", # pycodestyle: warning
1617
"UP", # pyupgrade
1718
"F", # pyflakes
1819
"SIM", # flake8-simplify
@@ -24,8 +25,23 @@ select = [
2425
"RUF", # ruff
2526
"G", # flake8-logging-format
2627
"TID", # flake8-tidy-imports
28+
"TCH", # flake8-type-checking
29+
"FA", # flake8-future-annotations
30+
"PL", # pylint
31+
]
32+
ignore = [
33+
"RUF001",
34+
"RUF002",
35+
"RUF003",
36+
"E203",
37+
"PERF203",
38+
"PLR09",
39+
"PLR2004",
40+
"PLR1702",
41+
"PLW1514",
42+
"PLW2901",
43+
"PLW0603",
2744
]
28-
ignore = ["RUF001", "RUF002", "RUF003", "E203", "PERF203", "F401", "F403"]
2945
preview = true
3046
3147
[tool.ruff.isort]

hydrogram/methods/messages/edit_message_media.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ async def edit_message_media(
120120
raw.functions.messages.UploadMedia(
121121
peer=await self.resolve_peer(chat_id),
122122
media=raw.types.InputMediaUploadedDocument(
123-
mime_type=self.guess_mime_type(media.media) or "video/mp4",
123+
mime_type=self.guess_mime_type(file_name or media.media.name)
124+
or "video/mp4",
124125
thumb=await self.save_file(media.thumb),
125126
spoiler=media.has_spoiler,
126127
file=await self.save_file(media.media),
@@ -159,7 +160,8 @@ async def edit_message_media(
159160
raw.functions.messages.UploadMedia(
160161
peer=await self.resolve_peer(chat_id),
161162
media=raw.types.InputMediaUploadedDocument(
162-
mime_type=self.guess_mime_type(media.media) or "audio/mpeg",
163+
mime_type=self.guess_mime_type(file_name or media.media.name)
164+
or "audio/mpeg",
163165
thumb=await self.save_file(media.thumb),
164166
file=await self.save_file(media.media),
165167
attributes=[
@@ -193,7 +195,8 @@ async def edit_message_media(
193195
raw.functions.messages.UploadMedia(
194196
peer=await self.resolve_peer(chat_id),
195197
media=raw.types.InputMediaUploadedDocument(
196-
mime_type=self.guess_mime_type(media.media) or "video/mp4",
198+
mime_type=self.guess_mime_type(file_name or media.media.name)
199+
or "video/mp4",
197200
thumb=await self.save_file(media.thumb),
198201
spoiler=media.has_spoiler,
199202
file=await self.save_file(media.media),
@@ -233,7 +236,8 @@ async def edit_message_media(
233236
raw.functions.messages.UploadMedia(
234237
peer=await self.resolve_peer(chat_id),
235238
media=raw.types.InputMediaUploadedDocument(
236-
mime_type=self.guess_mime_type(media.media) or "application/zip",
239+
mime_type=self.guess_mime_type(file_name or media.media.name)
240+
or "application/zip",
237241
thumb=await self.save_file(media.thumb),
238242
file=await self.save_file(media.media),
239243
attributes=[

hydrogram/types/input_media/input_media.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class InputMedia(Object):
4242
def __init__(
4343
self,
4444
media: str | BinaryIO,
45-
caption: str = "",
45+
caption: str | None = None,
4646
parse_mode: str | None = None,
4747
caption_entities: list[MessageEntity] | None = None,
4848
):

hydrogram/types/input_media/input_media_animation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class InputMediaAnimation(InputMedia):
3939
pass a binary file-like object with its attribute “.name” set for in-memory uploads or
4040
pass an HTTP URL as a string for Telegram to get an animation from the Internet.
4141
42-
thumb (``str``, *optional*):
42+
thumb (``str | BinaryIO``, *optional*):
4343
Thumbnail of the animation file sent.
4444
The thumbnail should be in JPEG format and less than 200 KB in size.
4545
A thumbnail's width and height should not exceed 320 pixels.
@@ -72,8 +72,8 @@ class InputMediaAnimation(InputMedia):
7272
def __init__(
7373
self,
7474
media: str | BinaryIO,
75-
thumb: str | None = None,
76-
caption: str = "",
75+
thumb: str | BinaryIO | None = None,
76+
caption: str | None = None,
7777
parse_mode: enums.ParseMode | None = None,
7878
caption_entities: list[MessageEntity] | None = None,
7979
width: int = 0,

hydrogram/types/input_media/input_media_audio.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class InputMediaAudio(InputMedia):
4141
pass a binary file-like object with its attribute “.name” set for in-memory uploads or
4242
pass an HTTP URL as a string for Telegram to get an audio file from the Internet.
4343
44-
thumb (``str``, *optional*):
44+
thumb (``str | BinaryIO``, *optional*):
4545
Thumbnail of the music file album cover.
4646
The thumbnail should be in JPEG format and less than 200 KB in size.
4747
A thumbnail's width and height should not exceed 320 pixels.
@@ -71,8 +71,8 @@ class InputMediaAudio(InputMedia):
7171
def __init__(
7272
self,
7373
media: str | BinaryIO,
74-
thumb: str | None = None,
75-
caption: str = "",
74+
thumb: str | BinaryIO | None = None,
75+
caption: str | None = None,
7676
parse_mode: enums.ParseMode | None = None,
7777
caption_entities: list[MessageEntity] | None = None,
7878
duration: int = 0,

hydrogram/types/input_media/input_media_document.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class InputMediaDocument(InputMedia):
3939
pass a binary file-like object with its attribute “.name” set for in-memory uploads or
4040
pass an HTTP URL as a string for Telegram to get a file from the Internet.
4141
42-
thumb (``str``):
42+
thumb (``str | BinaryIO``, *optional*):
4343
Thumbnail of the file sent.
4444
The thumbnail should be in JPEG format and less than 200 KB in size.
4545
A thumbnail's width and height should not exceed 320 pixels.
@@ -60,8 +60,8 @@ class InputMediaDocument(InputMedia):
6060
def __init__(
6161
self,
6262
media: str | BinaryIO,
63-
thumb: str | None = None,
64-
caption: str = "",
63+
thumb: str | BinaryIO | None = None,
64+
caption: str | None = None,
6565
parse_mode: enums.ParseMode | None = None,
6666
caption_entities: list[MessageEntity] | None = None,
6767
):

hydrogram/types/input_media/input_media_photo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class InputMediaPhoto(InputMedia):
5858
def __init__(
5959
self,
6060
media: str | BinaryIO,
61-
caption: str = "",
61+
caption: str | None = None,
6262
parse_mode: enums.ParseMode | None = None,
6363
caption_entities: list[MessageEntity] | None = None,
6464
has_spoiler: bool | None = None,

hydrogram/types/input_media/input_media_video.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class InputMediaVideo(InputMedia):
4040
pass a binary file-like object with its attribute “.name” set for in-memory uploads or
4141
pass an HTTP URL as a string for Telegram to get a video from the Internet.
4242
43-
thumb (``str``):
43+
thumb (``str | BinaryIO``, *optional*):
4444
Thumbnail of the video sent.
4545
The thumbnail should be in JPEG format and less than 200 KB in size.
4646
A thumbnail's width and height should not exceed 320 pixels.
@@ -76,8 +76,8 @@ class InputMediaVideo(InputMedia):
7676
def __init__(
7777
self,
7878
media: str | BinaryIO,
79-
thumb: str | None = None,
80-
caption: str = "",
79+
thumb: str | BinaryIO | None = None,
80+
caption: str | None = None,
8181
parse_mode: enums.ParseMode | None = None,
8282
caption_entities: list[MessageEntity] | None = None,
8383
width: int = 0,

hydrogram/types/messages_and_media/message.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ async def reply_animation(
13571357
duration: int = 0,
13581358
width: int = 0,
13591359
height: int = 0,
1360-
thumb: str | None = None,
1360+
thumb: str | BinaryIO | None = None,
13611361
disable_notification: bool | None = None,
13621362
reply_markup: types.InlineKeyboardMarkup
13631363
| types.ReplyKeyboardMarkup
@@ -1418,7 +1418,7 @@ async def reply_animation(
14181418
height (``int``, *optional*):
14191419
Animation height.
14201420
1421-
thumb (``str``, *optional*):
1421+
thumb (``str | BinaryIO``, *optional*):
14221422
Thumbnail of the animation file sent.
14231423
The thumbnail should be in JPEG format and less than 200 KB in size.
14241424
A thumbnail's width and height should not exceed 320 pixels.
@@ -1500,7 +1500,7 @@ async def reply_audio(
15001500
duration: int = 0,
15011501
performer: str | None = None,
15021502
title: str | None = None,
1503-
thumb: str | None = None,
1503+
thumb: str | BinaryIO | None = None,
15041504
disable_notification: bool | None = None,
15051505
reply_to_message_id: int | None = None,
15061506
reply_markup: types.InlineKeyboardMarkup
@@ -1556,7 +1556,7 @@ async def reply_audio(
15561556
title (``str``, *optional*):
15571557
Track name.
15581558
1559-
thumb (``str``, *optional*):
1559+
thumb (``str | BinaryIO``, *optional*):
15601560
Thumbnail of the music file album cover.
15611561
The thumbnail should be in JPEG format and less than 200 KB in size.
15621562
A thumbnail's width and height should not exceed 320 pixels.
@@ -1837,7 +1837,7 @@ async def reply_document(
18371837
self,
18381838
document: str | BinaryIO,
18391839
quote: bool | None = None,
1840-
thumb: str | None = None,
1840+
thumb: str | BinaryIO | None = None,
18411841
caption: str = "",
18421842
parse_mode: enums.ParseMode | None = None,
18431843
caption_entities: list[types.MessageEntity] | None = None,
@@ -1880,7 +1880,7 @@ async def reply_document(
18801880
If *reply_to_message_id* is passed, this parameter will be ignored.
18811881
Defaults to ``True`` in group chats and ``False`` in private chats.
18821882
1883-
thumb (``str``, *optional*):
1883+
thumb (``str | BinaryIO``, *optional*):
18841884
Thumbnail of the file sent.
18851885
The thumbnail should be in JPEG format and less than 200 KB in size.
18861886
A thumbnail's width and height should not exceed 320 pixels.
@@ -2725,7 +2725,7 @@ async def reply_video(
27252725
duration: int = 0,
27262726
width: int = 0,
27272727
height: int = 0,
2728-
thumb: str | None = None,
2728+
thumb: str | BinaryIO | None = None,
27292729
supports_streaming: bool = True,
27302730
disable_notification: bool | None = None,
27312731
reply_to_message_id: int | None = None,
@@ -2790,7 +2790,7 @@ async def reply_video(
27902790
height (``int``, *optional*):
27912791
Video height.
27922792
2793-
thumb (``str``, *optional*):
2793+
thumb (``str | BinaryIO``, *optional*):
27942794
Thumbnail of the video sent.
27952795
The thumbnail should be in JPEG format and less than 200 KB in size.
27962796
A thumbnail's width and height should not exceed 320 pixels.
@@ -2873,7 +2873,7 @@ async def reply_video_note(
28732873
quote: bool | None = None,
28742874
duration: int = 0,
28752875
length: int = 1,
2876-
thumb: str | None = None,
2876+
thumb: str | BinaryIO | None = None,
28772877
disable_notification: bool | None = None,
28782878
reply_to_message_id: int | None = None,
28792879
reply_markup: types.InlineKeyboardMarkup
@@ -2918,7 +2918,7 @@ async def reply_video_note(
29182918
length (``int``, *optional*):
29192919
Video width and height.
29202920
2921-
thumb (``str``, *optional*):
2921+
thumb (``str | BinaryIO``, *optional*):
29222922
Thumbnail of the video sent.
29232923
The thumbnail should be in JPEG format and less than 200 KB in size.
29242924
A thumbnail's width and height should not exceed 320 pixels.

0 commit comments

Comments
 (0)