Skip to content

Clarify Documentation and Type Hints of Input(Paid)Media #4762

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 20, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions changes/unreleased/4762.PbcJGM8KPBMbKri3fdHKjh.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
documentation = "Clarify Documentation and Type Hints of ``InputMedia`` and ``InputPaidMedia``. Note that the ``media`` parameter accepts only objects of type ``str`` and ``InputFile``. The respective subclasses of ``Input(Paid)Media`` each accept a broader range of input type for the ``media`` parameter."
[[pull_requests]]
uid = "4762"
author_uid = "Bibo-Joshi"
closes_threads = []
20 changes: 6 additions & 14 deletions telegram/_files/inputmedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,8 @@ class InputMedia(TelegramObject):

Args:
media_type (:obj:`str`): Type of media that the instance represents.
media (:obj:`str` | :term:`file object` | :class:`~telegram.InputFile` | :obj:`bytes` | \
:class:`pathlib.Path` | :class:`telegram.Animation` | :class:`telegram.Audio` | \
:class:`telegram.Document` | :class:`telegram.PhotoSize` | \
:class:`telegram.Video`): File to send.
media (:obj:`str` | :class:`~telegram.InputFile`): File to send.
|fileinputnopath|
Lastly you can pass an existing telegram media object of the corresponding type
to send.
caption (:obj:`str`, optional): Caption of the media to be sent,
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
Expand Down Expand Up @@ -89,7 +84,7 @@ class InputMedia(TelegramObject):
def __init__(
self,
media_type: str,
media: Union[str, InputFile, MediaType],
media: Union[str, InputFile],
caption: Optional[str] = None,
caption_entities: Optional[Sequence[MessageEntity]] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
Expand All @@ -98,7 +93,7 @@ def __init__(
):
super().__init__(api_kwargs=api_kwargs)
self.type: str = enum.get_member(constants.InputMediaType, media_type, media_type)
self.media: Union[str, InputFile, Animation, Audio, Document, PhotoSize, Video] = media
self.media: Union[str, InputFile] = media
self.caption: Optional[str] = caption
self.caption_entities: tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
self.parse_mode: ODVInput[str] = parse_mode
Expand Down Expand Up @@ -129,11 +124,8 @@ class InputPaidMedia(TelegramObject):

Args:
type (:obj:`str`): Type of media that the instance represents.
media (:obj:`str` | :term:`file object` | :class:`~telegram.InputFile` | :obj:`bytes` | \
:class:`pathlib.Path` | :class:`telegram.PhotoSize` | :class:`telegram.Video`): File
media (:obj:`str` | :class:`~telegram.InputFile`): File
to send. |fileinputnopath|
Lastly you can pass an existing telegram media object of the corresponding type
to send.

Attributes:
type (:obj:`str`): Type of the input media.
Expand All @@ -150,13 +142,13 @@ class InputPaidMedia(TelegramObject):
def __init__(
self,
type: str, # pylint: disable=redefined-builtin
media: Union[str, InputFile, PhotoSize, Video],
media: Union[str, InputFile],
*,
api_kwargs: Optional[JSONDict] = None,
):
super().__init__(api_kwargs=api_kwargs)
self.type: str = enum.get_member(constants.InputPaidMediaType, type, type)
self.media: Union[str, InputFile, PhotoSize, Video] = media
self.media: Union[str, InputFile] = media

self._freeze()

Expand Down
Loading