Skip to content
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

unify args and attributes docstrings in Chat class. #3302

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion telegram/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8205,7 +8205,7 @@ async def create_invoice_link(
api_kwargs=api_kwargs,
)

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict: # skipcq: PYL-W0613
"""See :meth:`telegram.TelegramObject.to_dict`."""
data: JSONDict = {"id": self.id, "username": self.username, "first_name": self.first_name}

Expand Down
24 changes: 16 additions & 8 deletions telegram/_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,28 @@ class Chat(TelegramObject):

.. versionadded:: 20.0
Attributes:
id (:obj:`int`): Unique identifier for this chat.
type (:obj:`str`): Type of chat.
id (:obj:`int`): Unique identifier for this chat. This number may be greater than 32 bits
and some programming languages may have difficulty/silent defects in interpreting it.
But it is smaller than 52 bits, so a signed 64-bit integer or double-precision float
type are safe for storing this identifier.
type (:obj:`str`): Type of chat, can be either :attr:`PRIVATE`, :attr:`GROUP`,
:attr:`SUPERGROUP` or :attr:`CHANNEL`.
title (:obj:`str`): Optional. Title, for supergroups, channels and group chats.
username (:obj:`str`): Optional. Username.
username (:obj:`str`): Optional. Username, for private chats, supergroups and channels if
available.
first_name (:obj:`str`): Optional. First name of the other party in a private chat.
last_name (:obj:`str`): Optional. Last name of the other party in a private chat.
photo (:class:`telegram.ChatPhoto`): Optional. Chat photo.
photo (:class:`telegram.ChatPhoto`): Optional. Chat photo.
Returned only in :meth:`telegram.Bot.get_chat`.
bio (:obj:`str`): Optional. Bio of the other party in a private chat. Returned only in
:meth:`telegram.Bot.get_chat`.
has_private_forwards (:obj:`bool`): Optional. :obj:`True`, if privacy settings of the other
party in the private chat allows to use ``tg://user?id=<user_id>`` links only in chats
with the user.
with the user. Returned only in :meth:`telegram.Bot.get_chat`.

.. versionadded:: 13.9
description (:obj:`str`): Optional. Description, for groups, supergroups and channel chats.
Returned only in :meth:`telegram.Bot.get_chat`.
invite_link (:obj:`str`): Optional. Primary invite link, for groups, supergroups and
channel. Returned only in :meth:`telegram.Bot.get_chat`.
pinned_message (:class:`telegram.Message`): Optional. The most recent pinned message
Expand All @@ -175,12 +182,13 @@ class Chat(TelegramObject):

.. versionadded:: 13.4
has_protected_content (:obj:`bool`): Optional. :obj:`True`, if messages from the chat can't
be forwarded to other chats.
be forwarded to other chats. Returned only in :meth:`telegram.Bot.get_chat`.

.. versionadded:: 13.9
sticker_set_name (:obj:`str`): Optional. For supergroups, name of Group sticker set.
sticker_set_name (:obj:`str`): Optional. For supergroups, name of Group sticker set.
Returned only in :meth:`telegram.Bot.get_chat`.
can_set_sticker_set (:obj:`bool`): Optional. :obj:`True`, if the bot can change group the
sticker set.
sticker set. Returned only in :meth:`telegram.Bot.get_chat`.
linked_chat_id (:obj:`int`): Optional. Unique identifier for the linked chat, i.e. the
discussion group identifier for a channel and vice versa; for supergroups and channel
chats. Returned only in :meth:`telegram.Bot.get_chat`.
Expand Down
4 changes: 2 additions & 2 deletions telegram/_chatinvitelink.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["ChatInviteLi

return super().de_json(data=data, bot=bot)

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict:
"""See :meth:`telegram.TelegramObject.to_dict`."""
data = super().to_dict()
data = super().to_dict(recursive=recursive)

data["expire_date"] = to_timestamp(self.expire_date)

Expand Down
4 changes: 2 additions & 2 deletions telegram/_chatjoinrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["ChatJoinRequ

return super().de_json(data=data, bot=bot)

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict:
"""See :meth:`telegram.TelegramObject.to_dict`."""
data = super().to_dict()
data = super().to_dict(recursive=recursive)

data["date"] = to_timestamp(self.date)

Expand Down
4 changes: 2 additions & 2 deletions telegram/_chatmember.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["ChatMember"]

return super().de_json(data=data, bot=bot)

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict:
"""See :meth:`telegram.TelegramObject.to_dict`."""
data = super().to_dict()
data = super().to_dict(recursive=recursive)

if data.get("until_date", False):
data["until_date"] = to_timestamp(data["until_date"])
Expand Down
4 changes: 2 additions & 2 deletions telegram/_chatmemberupdated.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["ChatMemberUp

return super().de_json(data=data, bot=bot)

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict:
"""See :meth:`telegram.TelegramObject.to_dict`."""
data = super().to_dict()
data = super().to_dict(recursive=recursive)

# Required
data["date"] = to_timestamp(self.date)
Expand Down
4 changes: 2 additions & 2 deletions telegram/_files/inputmedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def __init__(
self.caption_entities = caption_entities
self.parse_mode = parse_mode

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict:
"""See :meth:`telegram.TelegramObject.to_dict`."""
data = super().to_dict()
data = super().to_dict(recursive=recursive)

if self.caption_entities:
data["caption_entities"] = [ce.to_dict() for ce in self.caption_entities]
Expand Down
4 changes: 2 additions & 2 deletions telegram/_files/sticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["StickerSet"]

return super()._de_json(data=data, bot=bot, api_kwargs=api_kwargs)

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict:
"""See :meth:`telegram.TelegramObject.to_dict`."""
data = super().to_dict()
data = super().to_dict(recursive=recursive)

data["stickers"] = [s.to_dict() for s in data.get("stickers")] # type: ignore[union-attr]

Expand Down
4 changes: 2 additions & 2 deletions telegram/_games/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["Game"]:

return super().de_json(data=data, bot=bot)

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict:
"""See :meth:`telegram.TelegramObject.to_dict`."""
data = super().to_dict()
data = super().to_dict(recursive=recursive)

data["photo"] = [p.to_dict() for p in self.photo]
if self.text_entities:
Expand Down
4 changes: 2 additions & 2 deletions telegram/_inline/inlinekeyboardmarkup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def __init__(

self._id_attrs = (self.inline_keyboard,)

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict:
"""See :meth:`telegram.TelegramObject.to_dict`."""
data = super().to_dict()
data = super().to_dict(recursive=recursive)

data["inline_keyboard"] = []
for inline_keyboard in self.inline_keyboard:
Expand Down
4 changes: 2 additions & 2 deletions telegram/_inline/inlinequeryresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def __init__(self, type: str, id: str, *, api_kwargs: JSONDict = None):

self._id_attrs = (self.id,)

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict:
"""See :meth:`telegram.TelegramObject.to_dict`."""
data = super().to_dict()
data = super().to_dict(recursive=recursive)

# pylint: disable=no-member
if (
Expand Down
4 changes: 2 additions & 2 deletions telegram/_inline/inputinvoicemessagecontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ def __hash__(self) -> int:
)
)

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict:
"""See :meth:`telegram.TelegramObject.to_dict`."""
data = super().to_dict()
data = super().to_dict(recursive=recursive)

data["prices"] = [price.to_dict() for price in self.prices]

Expand Down
4 changes: 2 additions & 2 deletions telegram/_inline/inputtextmessagecontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def __init__(

self._id_attrs = (self.message_text,)

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict:
"""See :meth:`telegram.TelegramObject.to_dict`."""
data = super().to_dict()
data = super().to_dict(recursive=recursive)

if self.entities:
data["entities"] = [ce.to_dict() for ce in self.entities]
Expand Down
4 changes: 2 additions & 2 deletions telegram/_menubutton.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["MenuButtonWe

return super().de_json(data=data, bot=bot) # type: ignore[return-value]

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict:
"""See :meth:`telegram.TelegramObject.to_dict`."""
data = super().to_dict()
data = super().to_dict(recursive=recursive)
data["web_app"] = self.web_app.to_dict()
return data

Expand Down
7 changes: 4 additions & 3 deletions telegram/_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,10 +660,11 @@ def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["Message"]:
def effective_attachment(
self,
) -> Union[
Animation,
Audio,
Contact,
Dice,
Document,
Animation,
Game,
Invoice,
Location,
Expand Down Expand Up @@ -718,9 +719,9 @@ def effective_attachment(

return self._effective_attachment # type: ignore[return-value]

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict:
"""See :meth:`telegram.TelegramObject.to_dict`."""
data = super().to_dict()
data = super().to_dict(recursive=recursive)

# Required
data["date"] = to_timestamp(self.date)
Expand Down
12 changes: 6 additions & 6 deletions telegram/_passport/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,9 @@ def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["SecureValue"

return super().de_json(data=data, bot=bot)

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict:
"""See :meth:`telegram.TelegramObject.to_dict`."""
data = super().to_dict()
data = super().to_dict(recursive=recursive)

data["files"] = [p.to_dict() for p in self.files] # type: ignore[union-attr]
data["translation"] = [p.to_dict() for p in self.translation] # type: ignore[union-attr]
Expand Down Expand Up @@ -450,9 +450,9 @@ class DataCredentials(_CredentialsBase):
def __init__(self, data_hash: str, secret: str, *, api_kwargs: JSONDict = None):
super().__init__(hash=data_hash, secret=secret, api_kwargs=api_kwargs)

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict:
"""See :meth:`telegram.TelegramObject.to_dict`."""
data = super().to_dict()
data = super().to_dict(recursive=recursive)

del data["file_hash"]
del data["hash"]
Expand All @@ -479,9 +479,9 @@ class FileCredentials(_CredentialsBase):
def __init__(self, file_hash: str, secret: str, *, api_kwargs: JSONDict = None):
super().__init__(hash=file_hash, secret=secret, api_kwargs=api_kwargs)

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict:
"""See :meth:`telegram.TelegramObject.to_dict`."""
data = super().to_dict()
data = super().to_dict(recursive=recursive)

del data["data_hash"]
del data["hash"]
Expand Down
4 changes: 2 additions & 2 deletions telegram/_passport/encryptedpassportelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ def de_json_decrypted(

return super().de_json(data=data, bot=bot)

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict:
"""See :meth:`telegram.TelegramObject.to_dict`."""
data = super().to_dict()
data = super().to_dict(recursive=recursive)

if self.files:
data["files"] = [p.to_dict() for p in self.files]
Expand Down
4 changes: 2 additions & 2 deletions telegram/_passport/passportdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["PassportData

return super().de_json(data=data, bot=bot)

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict:
"""See :meth:`telegram.TelegramObject.to_dict`."""
data = super().to_dict()
data = super().to_dict(recursive=recursive)

data["data"] = [e.to_dict() for e in self.data]

Expand Down
4 changes: 2 additions & 2 deletions telegram/_payment/shippingoption.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ def __init__(

self._id_attrs = (self.id,)

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict:
"""See :meth:`telegram.TelegramObject.to_dict`."""
data = super().to_dict()
data = super().to_dict(recursive=recursive)

data["prices"] = [p.to_dict() for p in self.prices]

Expand Down
4 changes: 2 additions & 2 deletions telegram/_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["Poll"]:

return super().de_json(data=data, bot=bot)

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict:
"""See :meth:`telegram.TelegramObject.to_dict`."""
data = super().to_dict()
data = super().to_dict(recursive=recursive)

data["options"] = [x.to_dict() for x in self.options]
if self.explanation_entities:
Expand Down
4 changes: 2 additions & 2 deletions telegram/_replykeyboardmarkup.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ def __init__(

self._id_attrs = (self.keyboard,)

def to_dict(self) -> JSONDict:
def to_dict(self, recursive: bool = True) -> JSONDict:
"""See :meth:`telegram.TelegramObject.to_dict`."""
data = super().to_dict()
data = super().to_dict(recursive=recursive)

data["keyboard"] = []
for row in self.keyboard:
Expand Down