Skip to content

Commit f87f1a4

Browse files
committed
fix: return type of Client.download_media
1 parent 11439f3 commit f87f1a4

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

pyrogram/methods/messages/download_media.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import os
2020
from datetime import datetime
21+
from io import BytesIO
2122
from typing import Union, Optional, Callable, BinaryIO, List, Literal, overload
2223

2324
import pyrogram
@@ -137,7 +138,7 @@ async def download_media(
137138
block: bool = True,
138139
progress: Optional[Callable] = None,
139140
progress_args: tuple = ()
140-
) -> Union[str, BinaryIO, List[str], List[BinaryIO], None]:
141+
) -> Union[str, BytesIO, List[str], List[BytesIO], None]:
141142
"""Download the media from a message.
142143
143144
.. include:: /_includes/usable-by/users-bots.rst
@@ -185,7 +186,7 @@ async def download_media(
185186
You can either keep ``*args`` or add every single extra argument in your function signature.
186187
187188
Returns:
188-
``str`` | ``None`` | ``BinaryIO`` | ``List[str]`` | ``List[BinaryIO]``: On success, the absolute path of the downloaded file is returned,
189+
``str`` | ``None`` | ``BytesIO`` | ``List[str]`` | ``List[BytesIO]``: On success, the absolute path of the downloaded file is returned,
189190
otherwise, in case the download failed or was deliberately stopped with
190191
:meth:`~pyrogram.Client.stop_transmission`, None is returned.
191192
Otherwise, in case ``in_memory=True``, a binary file-like object with its attribute ".name" set is returned.

pyrogram/types/messages_and_media/message.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import logging
2121
from datetime import datetime
2222
from functools import partial
23+
from io import BytesIO
2324
from typing import BinaryIO, Callable, Dict, List, Match, Optional, Union
2425

2526
import pyrogram
@@ -9308,7 +9309,7 @@ async def download(
93089309
block: bool = True,
93099310
progress: Callable = None,
93109311
progress_args: tuple = ()
9311-
) -> str:
9312+
) -> Union[str, BytesIO, List[str], List[BytesIO], None]:
93129313
"""Shortcut for method :obj:`~pyrogram.Client.download_media` will automatically fill method attributes:
93139314
93149315
* message
@@ -9352,7 +9353,11 @@ async def download(
93529353
You can either keep ``*args`` or add every single extra argument in your function signature.
93539354
93549355
Returns:
9355-
On success, the absolute path of the downloaded file as string is returned, None otherwise.
9356+
``str`` | ``None`` | ``BytesIO`` | ``List[str]`` | ``List[BytesIO]``: On success, the absolute path of the downloaded file is returned,
9357+
otherwise, in case the download failed or was deliberately stopped with
9358+
:meth:`~pyrogram.Client.stop_transmission`, None is returned.
9359+
Otherwise, in case ``in_memory=True``, a binary file-like object with its attribute ".name" set is returned.
9360+
If the message contains multiple media (purchased paid media), a list of paths or binary file-like objects is returned.
93569361
93579362
Raises:
93589363
RPCError: In case of a Telegram RPC error.

pyrogram/types/messages_and_media/story.py

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

1919
from datetime import datetime
20+
from io import BytesIO
2021
from typing import BinaryIO, Callable, Dict, List, Optional, Union
2122

2223
import pyrogram
@@ -2064,7 +2065,7 @@ async def download(
20642065
block: bool = True,
20652066
progress: Callable = None,
20662067
progress_args: tuple = ()
2067-
) -> Optional[Union[str, BinaryIO]]:
2068+
) -> Optional[Union[str, BytesIO]]:
20682069
"""Bound method *download* of :obj:`~pyrogram.types.Story`.
20692070
20702071
Use as a shortcut for:
@@ -2117,7 +2118,10 @@ async def download(
21172118
You can either keep ``*args`` or add every single extra argument in your function signature.
21182119
21192120
Returns:
2120-
On success, the absolute path of the downloaded file as string is returned, None otherwise.
2121+
``str`` | ``None`` | ``BytesIO``: On success, the absolute path of the downloaded file is returned,
2122+
otherwise, in case the download failed or was deliberately stopped with
2123+
:meth:`~pyrogram.Client.stop_transmission`, None is returned.
2124+
Otherwise, in case ``in_memory=True``, a binary file-like object with its attribute ".name" set is returned.
21212125
21222126
Raises:
21232127
RPCError: In case of a Telegram RPC error.

0 commit comments

Comments
 (0)