Skip to content

Commit 27e313f

Browse files
Fix up type hints,
Replace BinaryIO with BytesIO Follow-Up: 7b85393 Co-authored-by: Ryuk <[email protected]>
1 parent adf3565 commit 27e313f

24 files changed

+138
-115
lines changed

pyrogram/methods/advanced/save_file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import os
2626
from hashlib import md5
2727
from pathlib import PurePath
28-
from typing import Union, BinaryIO, Callable
28+
from typing import Union, Callable
2929

3030
import pyrogram
3131
from pyrogram import StopTransmission
@@ -38,7 +38,7 @@
3838
class SaveFile:
3939
async def save_file(
4040
self: "pyrogram.Client",
41-
path: Union[str, BinaryIO],
41+
path: Union[str, "io.BytesIO"],
4242
file_id: int = None,
4343
file_part: int = 0,
4444
progress: Callable = None,
@@ -54,7 +54,7 @@ async def save_file(
5454
available yet in the Client class as an easy-to-use method).
5555
5656
Parameters:
57-
path (``str`` | ``BinaryIO``):
57+
path (``str`` | :obj:`io.BytesIO`):
5858
The path of the file you want to upload that exists on your local machine or a binary file-like object
5959
with its attribute ".name" set for in-memory uploads.
6060

pyrogram/methods/chats/set_chat_photo.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19+
import io
1920
import os
20-
from typing import Union, BinaryIO
21+
from typing import Union
2122

2223
import pyrogram
2324
from pyrogram import raw, types, utils
@@ -29,8 +30,8 @@ async def set_chat_photo(
2930
self: "pyrogram.Client",
3031
chat_id: Union[int, str],
3132
*,
32-
photo: Union[str, BinaryIO] = None,
33-
video: Union[str, BinaryIO] = None,
33+
photo: Union[str, "io.BytesIO"] = None,
34+
video: Union[str, "io.BytesIO"] = None,
3435
video_start_ts: float = None,
3536
) -> Union["types.Message", bool]:
3637
"""Set a new chat photo or video (H.264/MPEG-4 AVC video, max 5 seconds).
@@ -46,12 +47,12 @@ async def set_chat_photo(
4647
chat_id (``int`` | ``str``):
4748
Unique identifier (int) or username (str) of the target chat.
4849
49-
photo (``str`` | ``BinaryIO``, *optional*):
50+
photo (``str`` | :obj:`io.BytesIO`, *optional*):
5051
New chat photo. You can pass a :obj:`~pyrogram.types.Photo` file_id, a file path to upload a new photo
5152
from your local machine or a binary file-like object with its attribute
5253
".name" set for in-memory uploads.
5354
54-
video (``str`` | ``BinaryIO``, *optional*):
55+
video (``str`` | :obj:`io.BytesIO`, *optional*):
5556
New chat video. You can pass a :obj:`~pyrogram.types.Video` file_id, a file path to upload a new video
5657
from your local machine or a binary file-like object with its attribute
5758
".name" set for in-memory uploads.

pyrogram/methods/messages/download_media.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import asyncio
20+
import io
2021
import os
2122
from datetime import datetime
22-
from typing import Union, Optional, Callable, BinaryIO
23+
from typing import Union, Optional, Callable
2324

2425
import pyrogram
2526
from pyrogram import types, enums
@@ -37,7 +38,7 @@ async def download_media(
3738
block: bool = True,
3839
progress: Callable = None,
3940
progress_args: tuple = ()
40-
) -> Optional[Union[str, BinaryIO]]:
41+
) -> Optional[Union[str, "io.BytesIO"]]:
4142
"""Download the media from a message.
4243
4344
.. include:: /_includes/usable-by/users-bots.rst
@@ -85,7 +86,7 @@ async def download_media(
8586
You can either keep ``*args`` or add every single extra argument in your function signature.
8687
8788
Returns:
88-
``str`` | ``None`` | ``BinaryIO``: On success, the absolute path of the downloaded file is returned,
89+
``str`` | ``None`` | :obj:`io.BytesIO`: On success, the absolute path of the downloaded file is returned,
8990
otherwise, in case the download failed or was deliberately stopped with
9091
:meth:`~pyrogram.Client.stop_transmission`, None is returned.
9192
Otherwise, in case ``in_memory=True``, a binary file-like object with its attribute ".name" set is returned.

pyrogram/methods/messages/send_animation.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import logging
20+
import io
2021
import os
2122
import re
2223
from datetime import datetime
23-
from typing import Union, BinaryIO, List, Optional, Callable
24+
from typing import Union, List, Optional, Callable
2425

2526
import pyrogram
2627
from pyrogram import StopTransmission, enums, raw, types, utils
@@ -35,7 +36,7 @@ class SendAnimation:
3536
async def send_animation(
3637
self: "pyrogram.Client",
3738
chat_id: Union[int, str],
38-
animation: Union[str, BinaryIO],
39+
animation: Union[str, "io.BytesIO"],
3940
caption: str = "",
4041
parse_mode: Optional["enums.ParseMode"] = None,
4142
caption_entities: List["types.MessageEntity"] = None,
@@ -45,7 +46,7 @@ async def send_animation(
4546
duration: int = 0,
4647
width: int = 0,
4748
height: int = 0,
48-
thumb: Union[str, BinaryIO] = None,
49+
thumb: Union[str, "io.BytesIO"] = None,
4950
file_name: str = None,
5051
disable_notification: bool = None,
5152
reply_parameters: "types.ReplyParameters" = None,
@@ -77,7 +78,7 @@ async def send_animation(
7778
For your personal cloud (Saved Messages) you can simply use "me" or "self".
7879
For a contact that exists in your Telegram address book you can use his phone number (str).
7980
80-
animation (``str`` | ``BinaryIO``):
81+
animation (``str`` | :obj:`io.BytesIO`):
8182
Animation to send.
8283
Pass a file_id as string to send an animation that exists on the Telegram servers,
8384
pass an HTTP URL as a string for Telegram to get an animation from the Internet,
@@ -113,7 +114,7 @@ async def send_animation(
113114
height (``int``, *optional*):
114115
Animation height.
115116
116-
thumb (``str`` | ``BinaryIO``, *optional*):
117+
thumb (``str`` | :obj:`io.BytesIO`, *optional*):
117118
Thumbnail of the animation file sent.
118119
The thumbnail should be in JPEG format and less than 200 KB in size.
119120
A thumbnail's width and height should not exceed 320 pixels.

pyrogram/methods/messages/send_audio.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import logging
20+
import io
2021
import os
2122
import re
2223
from datetime import datetime
23-
from typing import Union, BinaryIO, List, Optional, Callable
24+
from typing import Union, List, Optional, Callable
2425

2526
import pyrogram
2627
from pyrogram import StopTransmission, enums, raw, types, utils
@@ -35,14 +36,14 @@ class SendAudio:
3536
async def send_audio(
3637
self: "pyrogram.Client",
3738
chat_id: Union[int, str],
38-
audio: Union[str, BinaryIO],
39+
audio: Union[str, "io.BytesIO"],
3940
caption: str = "",
4041
parse_mode: Optional["enums.ParseMode"] = None,
4142
caption_entities: List["types.MessageEntity"] = None,
4243
duration: int = 0,
4344
performer: str = None,
4445
title: str = None,
45-
thumb: Union[str, BinaryIO] = None,
46+
thumb: Union[str, "io.BytesIO"] = None,
4647
file_name: str = None,
4748
disable_notification: bool = None,
4849
reply_parameters: "types.ReplyParameters" = None,
@@ -75,7 +76,7 @@ async def send_audio(
7576
For your personal cloud (Saved Messages) you can simply use "me" or "self".
7677
For a contact that exists in your Telegram address book you can use his phone number (str).
7778
78-
audio (``str`` | ``BinaryIO``):
79+
audio (``str`` | :obj:`io.BytesIO`):
7980
Audio file to send.
8081
Pass a file_id as string to send an audio file that exists on the Telegram servers,
8182
pass an HTTP URL as a string for Telegram to get an audio file from the Internet,
@@ -101,7 +102,7 @@ async def send_audio(
101102
title (``str``, *optional*):
102103
Track name.
103104
104-
thumb (``str`` | ``BinaryIO``, *optional*):
105+
thumb (``str`` | :obj:`io.BytesIO`, *optional*):
105106
Thumbnail of the music file album cover.
106107
The thumbnail should be in JPEG format and less than 200 KB in size.
107108
A thumbnail's width and height should not exceed 320 pixels.

pyrogram/methods/messages/send_document.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import logging
20+
import io
2021
import os
2122
import re
2223
from datetime import datetime
23-
from typing import Union, BinaryIO, List, Optional, Callable
24+
from typing import Union, List, Optional, Callable
2425

2526
import pyrogram
2627
from pyrogram import StopTransmission, enums, raw, types, utils
@@ -35,8 +36,8 @@ class SendDocument:
3536
async def send_document(
3637
self: "pyrogram.Client",
3738
chat_id: Union[int, str],
38-
document: Union[str, BinaryIO],
39-
thumb: Union[str, BinaryIO] = None,
39+
document: Union[str, "io.BytesIO"],
40+
thumb: Union[str, "io.BytesIO"] = None,
4041
caption: str = "",
4142
parse_mode: Optional["enums.ParseMode"] = None,
4243
caption_entities: List["types.MessageEntity"] = None,
@@ -72,14 +73,14 @@ async def send_document(
7273
For your personal cloud (Saved Messages) you can simply use "me" or "self".
7374
For a contact that exists in your Telegram address book you can use his phone number (str).
7475
75-
document (``str`` | ``BinaryIO``):
76+
document (``str`` | :obj:`io.BytesIO`):
7677
File to send.
7778
Pass a file_id as string to send a file that exists on the Telegram servers,
7879
pass an HTTP URL as a string for Telegram to get a file from the Internet,
7980
pass a file path as string to upload a new file that exists on your local machine, or
8081
pass a binary file-like object with its attribute ".name" set for in-memory uploads.
8182
82-
thumb (``str`` | ``BinaryIO``, *optional*):
83+
thumb (``str`` | :obj:`io.BytesIO`, *optional*):
8384
Thumbnail of the file sent.
8485
The thumbnail should be in JPEG format and less than 200 KB in size.
8586
A thumbnail's width and height should not exceed 320 pixels.

pyrogram/methods/messages/send_photo.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import logging
20+
import io
2021
import os
2122
import re
2223
from datetime import datetime
23-
from typing import Union, BinaryIO, List, Optional, Callable
24+
from typing import Union, List, Optional, Callable
2425

2526
import pyrogram
2627
from pyrogram import raw, enums, types, utils
@@ -35,7 +36,7 @@ class SendPhoto:
3536
async def send_photo(
3637
self: "pyrogram.Client",
3738
chat_id: Union[int, str],
38-
photo: Union[str, BinaryIO],
39+
photo: Union[str, "io.BytesIO"],
3940
caption: str = "",
4041
parse_mode: Optional["enums.ParseMode"] = None,
4142
caption_entities: List["types.MessageEntity"] = None,
@@ -72,7 +73,7 @@ async def send_photo(
7273
For your personal cloud (Saved Messages) you can simply use "me" or "self".
7374
For a contact that exists in your Telegram address book you can use his phone number (str).
7475
75-
photo (``str`` | ``BinaryIO``):
76+
photo (``str`` | :obj:`io.BytesIO`):
7677
Photo to send.
7778
Pass a file_id as string to send a photo that exists on the Telegram servers,
7879
pass an HTTP URL as a string for Telegram to get a photo from the Internet,

pyrogram/methods/messages/send_sticker.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import logging
20+
import io
2021
import os
2122
import re
2223
from datetime import datetime
23-
from typing import List, Union, BinaryIO, Optional, Callable
24+
from typing import List, Union, Optional, Callable
2425

2526
import pyrogram
2627
from pyrogram import StopTransmission, raw, types, utils
@@ -35,7 +36,7 @@ class SendSticker:
3536
async def send_sticker(
3637
self: "pyrogram.Client",
3738
chat_id: Union[int, str],
38-
sticker: Union[str, BinaryIO],
39+
sticker: Union[str, "io.BytesIO"],
3940
caption: str = "",
4041
parse_mode: Optional["enums.ParseMode"] = None,
4142
caption_entities: List["types.MessageEntity"] = None,
@@ -69,7 +70,7 @@ async def send_sticker(
6970
For your personal cloud (Saved Messages) you can simply use "me" or "self".
7071
For a contact that exists in your Telegram address book you can use his phone number (str).
7172
72-
sticker (``str`` | ``BinaryIO``):
73+
sticker (``str`` | :obj:`io.BytesIO`):
7374
Sticker to send.
7475
Pass a file_id as string to send a sticker that exists on the Telegram servers,
7576
pass an HTTP URL as a string for Telegram to get a .webp sticker file from the Internet,

pyrogram/methods/messages/send_video.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import logging
20+
import io
2021
import os
2122
import re
2223
from datetime import datetime
23-
from typing import Union, BinaryIO, List, Optional, Callable
24+
from typing import Union, List, Optional, Callable
2425

2526
import pyrogram
2627
from pyrogram import StopTransmission, enums, raw, types, utils
@@ -35,15 +36,15 @@ class SendVideo:
3536
async def send_video(
3637
self: "pyrogram.Client",
3738
chat_id: Union[int, str],
38-
video: Union[str, BinaryIO],
39+
video: Union[str, "io.BytesIO"],
3940
caption: str = "",
4041
parse_mode: Optional["enums.ParseMode"] = None,
4142
caption_entities: List["types.MessageEntity"] = None,
4243
show_caption_above_media: bool = None,
4344
duration: int = 0,
4445
width: int = 0,
4546
height: int = 0,
46-
thumb: Union[str, BinaryIO] = None,
47+
thumb: Union[str, "io.BytesIO"] = None,
4748
has_spoiler: bool = None,
4849
supports_streaming: bool = True,
4950
disable_notification: bool = None,
@@ -79,7 +80,7 @@ async def send_video(
7980
For your personal cloud (Saved Messages) you can simply use "me" or "self".
8081
For a contact that exists in your Telegram address book you can use his phone number (str).
8182
82-
video (``str`` | ``BinaryIO``):
83+
video (``str`` | :obj:`io.BytesIO`):
8384
Video to send.
8485
Pass a file_id as string to send a video that exists on the Telegram servers,
8586
pass an HTTP URL as a string for Telegram to get a video from the Internet,
@@ -108,7 +109,7 @@ async def send_video(
108109
height (``int``, *optional*):
109110
Video height.
110111
111-
thumb (``str`` | ``BinaryIO``, *optional*):
112+
thumb (``str`` | :obj:`io.BytesIO`, *optional*):
112113
Thumbnail of the video sent.
113114
The thumbnail should be in JPEG format and less than 200 KB in size.
114115
A thumbnail's width and height should not exceed 320 pixels.

pyrogram/methods/messages/send_video_note.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import logging
20+
import io
2021
import os
2122
from datetime import datetime
22-
from typing import List, Union, BinaryIO, Optional, Callable
23+
from typing import List, Union, Optional, Callable
2324

2425
import pyrogram
2526
from pyrogram import StopTransmission, raw, types, utils
@@ -34,10 +35,10 @@ class SendVideoNote:
3435
async def send_video_note(
3536
self: "pyrogram.Client",
3637
chat_id: Union[int, str],
37-
video_note: Union[str, BinaryIO],
38+
video_note: Union[str, "io.BytesIO"],
3839
duration: int = 0,
3940
length: int = 1,
40-
thumb: Union[str, BinaryIO] = None,
41+
thumb: Union[str, "io.BytesIO"] = None,
4142
disable_notification: bool = None,
4243
protect_content: bool = None,
4344
allow_paid_broadcast: bool = None,
@@ -72,7 +73,7 @@ async def send_video_note(
7273
For your personal cloud (Saved Messages) you can simply use "me" or "self".
7374
For a contact that exists in your Telegram address book you can use his phone number (str).
7475
75-
video_note (``str`` | ``BinaryIO``):
76+
video_note (``str`` | :obj:`io.BytesIO`):
7677
Video note to send.
7778
Pass a file_id as string to send a video note that exists on the Telegram servers,
7879
pass a file path as string to upload a new video note that exists on your local machine, or
@@ -85,7 +86,7 @@ async def send_video_note(
8586
length (``int``, *optional*):
8687
Video width and height.
8788
88-
thumb (``str`` | ``BinaryIO``, *optional*):
89+
thumb (``str`` | :obj:`io.BytesIO`, *optional*):
8990
Thumbnail of the video sent.
9091
The thumbnail should be in JPEG format and less than 200 KB in size.
9192
A thumbnail's width and height should not exceed 320 pixels.

0 commit comments

Comments
 (0)