Skip to content

Commit 05a3cea

Browse files
committed
add tiny docstring and typing fixes
1 parent f1cdfd7 commit 05a3cea

3 files changed

Lines changed: 110 additions & 57 deletions

File tree

pyrogram/media_utils.py

Lines changed: 98 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import io
22
import os
33
import re
4-
from typing import BinaryIO, Callable, Union, cast
4+
from typing import BinaryIO, Callable, Optional, Union, cast
55

66
import pyrogram
77
from pyrogram import raw
@@ -13,23 +13,30 @@
1313
async def resolve_to_raw_photo(
1414
client: "pyrogram.Client",
1515
media: "types.InputMediaPhoto",
16-
chat_id: Union[int, str, None] = None,
16+
chat_id: Optional[Union[int, str]] = None,
1717
) -> Union[
1818
raw.types.InputMediaPhoto,
1919
raw.types.InputMediaPhotoExternal,
2020
raw.types.InputMediaDocument,
2121
]:
2222
"""
2323
Prepare the photo to be sent in raw
24+
2425
Parameters:
25-
client (``pyrogram.Client``):
26+
client (:obj:`~pyrogram.Client`):
2627
The client instance
27-
media (``types.InputMediaPhoto``):
28+
29+
media (:obj:`~pyrogram.types.InputMediaPhoto`):
2830
The media to be sent
29-
chat_id (``int`` | ``str`` | ``None``):
31+
32+
chat_id (``int`` | ``str``, *optional*):
3033
The chat id to send the media
34+
3135
Returns:
32-
:obj:`~pyrogram.raw.types.InputMediaPhoto|pyrogram.raw.types.InputMediaPhotoExternal`: On success, the resolved media is returned in form of an InputMediaPhoto object.
36+
:obj:`~pyrogram.raw.types.InputMediaPhoto`
37+
| :obj:`~pyrogram.raw.types.InputMediaPhotoExternal`: On success,
38+
the resolved media is returned in form of a proper object.
39+
3340
Raises:
3441
RPCError: In case of a Telegram RPC error.
3542
"""
@@ -71,22 +78,30 @@ async def resolve_to_raw_photo(
7178
async def resolve_to_raw_video(
7279
client: "pyrogram.Client",
7380
media: "types.InputMediaVideo",
74-
file_name: Union[str, None] = None,
75-
chat_id: Union[int, str, None] = None,
81+
file_name: Optional[str] = None,
82+
chat_id: Optional[Union[int, str]] = None,
7683
) -> Union[raw.types.InputMediaDocument, raw.types.InputMediaDocumentExternal]:
7784
"""
7885
Prepare the video to be sent in raw
86+
7987
Parameters:
80-
client (``pyrogram.Client``):
88+
client (:obj:`~pyrogram.Client`):
8189
The client instance
82-
media (``types.InputMediaVideo``):
90+
91+
media (:obj:`~pyrogram.types.InputMediaVideo`):
8392
The media to be sent
84-
file_name (``str`` | ``None``):
93+
94+
file_name (``str``, *optional*):
8595
The name of the file
86-
chat_id (``int`` | ``str`` | ``None``):
96+
97+
chat_id (``int`` | ``str``, *optional*):
8798
The chat id to send the media
99+
88100
Returns:
89-
:obj:`~pyrogram.raw.types.InputMediaDocument|pyrogram.raw.types.InputMediaDocumentExternal`: On success, the resolved media is returned in form of an InputMediaDocument|InputMediaDocumentExternal object.
101+
:obj:`~pyrogram.raw.types.InputMediaDocument`
102+
| :obj:`~pyrogram.raw.types.InputMediaDocumentExternal`: On success,
103+
the resolved media is returned in form of a proper object.
104+
90105
Raises:
91106
RPCError: In case of a Telegram RPC error.
92107
"""
@@ -141,22 +156,30 @@ async def resolve_to_raw_video(
141156
async def resolve_to_raw_audio(
142157
client: "pyrogram.Client",
143158
media: "types.InputMediaAudio",
144-
file_name: Union[str, None] = None,
145-
chat_id: Union[int, str, None] = None,
159+
file_name: Optional[str] = None,
160+
chat_id: Optional[Union[int, str]] = None,
146161
) -> Union[raw.types.InputMediaDocument, raw.types.InputMediaDocumentExternal]:
147162
"""
148163
Prepare the audio to be sent in raw
164+
149165
Parameters:
150-
client (``pyrogram.Client``):
166+
client (:obj:`~pyrogram.Client`):
151167
The client instance
152-
media (``types.InputMediaAudio``):
168+
169+
media (:obj:`~pyrogram.types.InputMediaAudio`):
153170
The media to be sent
154-
file_name (``str`` | ``None``):
171+
172+
file_name (``str``, *optional*):
155173
The name of the file
156-
chat_id (``int`` | ``str`` | ``None``):
174+
175+
chat_id (``int`` | ``str``, *optional*):
157176
The chat id to send the media
177+
158178
Returns:
159-
:obj:`~pyrogram.raw.types.InputMediaDocument|pyrogram.raw.types.InputMediaDocumentExternal`: On success, the resolved media is returned in form of an InputMediaDocument|InputMediaDocumentExternal object.
179+
:obj:`~pyrogram.raw.types.InputMediaDocument`
180+
| :obj:`~pyrogram.raw.types.InputMediaDocumentExternal`: On success,
181+
the resolved media is returned in form of a proper object.
182+
160183
Raises:
161184
RPCError: In case of a Telegram RPC error.
162185
"""
@@ -203,22 +226,30 @@ async def resolve_to_raw_audio(
203226
async def resolve_to_raw_animation(
204227
client: "pyrogram.Client",
205228
media: "types.InputMediaAnimation",
206-
file_name: Union[str, None] = None,
207-
chat_id: Union[int, str, None] = None,
229+
file_name: Optional[str] = None,
230+
chat_id: Optional[Union[int, str]] = None,
208231
) -> Union[raw.types.InputMediaDocument, raw.types.InputMediaDocumentExternal]:
209232
"""
210233
Prepare the animation to be sent in raw
234+
211235
Parameters:
212-
client (``pyrogram.Client``):
236+
client (:obj:`~pyrogram.Client`):
213237
The client instance
214-
media (``types.InputMediaAnimation``):
238+
239+
media (:obj:`~pyrogram.types.InputMediaAnimation`):
215240
The media to be sent
216-
file_name (``str`` | ``None``):
241+
242+
file_name (``str``, *optional*):
217243
The name of the file
218-
chat_id (``int`` | ``str`` | ``None``):
244+
245+
chat_id (``int`` | ``str``, *optional*):
219246
The chat id to send the media
247+
220248
Returns:
221-
:obj:`~pyrogram.raw.types.InputMediaDocument|pyrogram.raw.types.InputMediaDocumentExternal`: On success, the resolved media is returned in form of an InputMediaDocument|InputMediaDocumentExternal object.
249+
:obj:`~pyrogram.raw.types.InputMediaDocument`
250+
| :obj:`~pyrogram.raw.types.InputMediaDocumentExternal`: On success,
251+
the resolved media is returned in form of a proper object.
252+
222253
Raises:
223254
RPCError: In case of a Telegram RPC error.
224255
"""
@@ -274,22 +305,30 @@ async def resolve_to_raw_animation(
274305
async def resolve_to_raw_document(
275306
client: "pyrogram.Client",
276307
media: "types.InputMediaDocument",
277-
file_name: Union[str, None] = None,
278-
chat_id: Union[int, str, None] = None,
308+
file_name: Optional[str] = None,
309+
chat_id: Optional[Union[int, str]] = None,
279310
) -> Union[raw.types.InputMediaDocument, raw.types.InputMediaDocumentExternal]:
280311
"""
281312
Prepare the document to be sent in raw
313+
282314
Parameters:
283-
client (``pyrogram.Client``):
315+
client (:obj:`~pyrogram.Client`):
284316
The client instance
285-
media (``types.InputMediaDocument``):
317+
318+
media (:obj:`~pyrogram.types.InputMediaDocument`):
286319
The media to be sent
287-
file_name (``str`` | ``None``):
320+
321+
file_name (``str``, *optional*):
288322
The name of the file
289-
chat_id (``int`` | ``str`` | ``None``):
323+
324+
chat_id (``int`` | ``str``, *optional*):
290325
The chat id to send the media
326+
291327
Returns:
292-
:obj:`~pyrogram.raw.types.InputMediaDocument|pyrogram.raw.types.InputMediaDocumentExternal`: On success, the resolved media is returned in form of an InputMediaDocument|InputMediaDocumentExternal object.
328+
:obj:`~pyrogram.raw.types.InputMediaDocument`
329+
| :obj:`~pyrogram.raw.types.InputMediaDocumentExternal`: On success,
330+
the resolved media is returned in form of a proper object.
331+
293332
Raises:
294333
RPCError: In case of a Telegram RPC error.
295334
"""
@@ -333,12 +372,15 @@ async def resolve_to_raw_location(
333372
) -> Union[raw.types.InputMediaGeoLive, raw.types.InputMediaGeoPoint]:
334373
"""
335374
Prepare the location to be sent in raw
375+
336376
Parameters:
337-
loc (``types.Location``):
377+
loc (:obj:`~pyrogram.types.Location`):
338378
The location to be sent
379+
339380
Returns:
340-
:obj:`~pyrogram.raw.types.InputMediaGeoLive|pyrogram.raw.types.InputMediaGeoPoint`:
341-
On success, the resolved media is returned in form of an InputMediaGeoLive|InputMediaGeoPoint object.
381+
:obj:`~pyrogram.raw.types.InputMediaGeoLive`
382+
| :obj:`~pyrogram.raw.types.InputMediaGeoPoint`: On success,
383+
the resolved media is returned in form of a proper object.
342384
"""
343385
if loc.live_period is not None:
344386
return raw.types.InputMediaGeoLive(
@@ -363,30 +405,39 @@ async def resolve_to_raw_location(
363405
async def resolve_to_raw_sticker(
364406
client: "pyrogram.Client",
365407
sticker: "types.InputMediaSticker",
366-
emoji: str = "",
367-
progress: Union[Callable, None] = None,
368-
progress_args: tuple = (),
408+
emoji: Optional[str] = "",
409+
progress: Optional[Callable] = None,
410+
progress_args: Optional[tuple] = (),
369411
) -> Union[
370412
raw.types.InputMediaUploadedDocument,
371413
raw.types.InputMediaDocumentExternal,
372414
raw.types.InputMediaDocument,
373415
]:
374416
"""
375417
Prepare the sticker to be sent in raw
418+
376419
Parameters:
377-
client (``pyrogram.Client``):
420+
client (:obj:`~pyrogram.Client`):
378421
The client instance
379-
sticker (``types.InputMediaSticker``):
422+
423+
sticker (:obj:`~pyrogram.types.InputMediaSticker`):
380424
The media to be sent
381-
emoji (``str``):
425+
426+
emoji (``str``, *optional*):
382427
The emoji to be associated with the sticker
383-
progress (``Callable``):
428+
429+
progress (``Callable``, *optional*):
384430
A callable to be called with the progress of the upload
385-
progress_args (``tuple``):
431+
432+
progress_args (``tuple``, *optional*):
386433
The arguments to be passed to the progress callable
434+
387435
Returns:
388-
:obj:`~pyrogram.raw.types.InputMediaUploadedDocument|pyrogram.raw.types.InputMediaDocumentExternal|pyrogram.raw.types.InputMediaDocument`:
389-
On success, the resolved media is returned in form of an InputMediaUploadedDocument|InputMediaDocumentExternal|InputMediaDocument object.
436+
:obj:`~pyrogram.raw.types.InputMediaUploadedDocument`
437+
| :obj:`~pyrogram.raw.types.InputMediaDocumentExternal`
438+
| :obj:`~pyrogram.raw.types.InputMediaDocument`: On success, the resolved
439+
media is returned in form of a proper object.
440+
390441
Raises:
391442
RPCError: In case of a Telegram RPC error.
392443
"""

pyrogram/types/input_content/input_media_sticker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from .input_media import InputMedia
2222

2323
class InputMediaSticker(InputMedia):
24-
"""A sticker to be attached
24+
"""A sticker to be attached.
2525
2626
Parameters:
2727
media (``str`` | ``BinaryIO``):

pyrogram/types/input_content/input_poll_option.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
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-
from typing import Union
19+
from typing import Optional, Union
2020

2121
import pyrogram
2222
from pyrogram import raw, types, media_utils
@@ -30,20 +30,22 @@ class InputPollOption(Object):
3030
Parameters:
3131
text (``str`` | :obj:`~pyrogram.enums.FormattedText`, *optional*):
3232
Option text, 1-100 characters.
33-
media (``str`` | :obj:`pyrogram.types.InputMediaPhoto|pyrogram.types.InputMediaVideo|pyrogram.types.Location|str`, *optional*):
34-
Media associated with the option. (photo, video, location, sticker)
33+
34+
media (:obj:`~pyrogram.types.InputMediaPhoto` | :obj:`~pyrogram.types.InputMediaVideo` | :obj:`~pyrogram.types.InputMediaSticker` | :obj:`~pyrogram.types.Location`, *optional*):
35+
Media associated with the option. (photo, video, sticker, location)
3536
"""
3637

3738
def __init__(
3839
self,
3940
*,
4041
text: Union[str, "types.FormattedText"],
41-
media: Union[
42-
"types.InputMediaPhoto",
43-
"types.InputMediaVideo",
44-
"types.InputMediaSticker",
45-
"types.Location",
46-
None,
42+
media: Optional[
43+
Union[
44+
"types.InputMediaPhoto",
45+
"types.InputMediaVideo",
46+
"types.InputMediaSticker",
47+
"types.Location",
48+
]
4749
] = None,
4850
):
4951
super().__init__()

0 commit comments

Comments
 (0)