mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-14 03:41:49 +01:00
Use de_json
instead of de_json_wo
for required args
This commit is contained in:
parent
3fe033d30a
commit
c5f3bf7e82
24 changed files with 43 additions and 52 deletions
|
@ -114,7 +114,7 @@ class BusinessConnection(TelegramObject):
|
|||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["date"] = from_timestamp(data.get("date"), tzinfo=loc_tzinfo)
|
||||
data["user"] = de_json_wo(data.get("user"), User, bot)
|
||||
data["user"] = User.de_json(data["user"], bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
@ -176,7 +176,7 @@ class BusinessMessagesDeleted(TelegramObject):
|
|||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["chat"] = de_json_wo(data.get("chat"), Chat, bot)
|
||||
data["chat"] = Chat.de_json(data["chat"], bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ from telegram import constants
|
|||
from telegram._files.document import Document
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils import enum
|
||||
from telegram._utils.argumentparsing import de_json_wo, parse_sequence_arg
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -280,10 +280,10 @@ class BackgroundType(TelegramObject):
|
|||
return _class_mapping[data.pop("type")].de_json(data=data, bot=bot)
|
||||
|
||||
if "fill" in data:
|
||||
data["fill"] = de_json_wo(data.get("fill"), BackgroundFill, bot)
|
||||
data["fill"] = BackgroundFill.de_json(data["fill"], bot)
|
||||
|
||||
if "document" in data:
|
||||
data["document"] = de_json_wo(data.get("document"), Document, bot)
|
||||
data["document"] = Document.de_json(data["document"], bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
@ -527,6 +527,6 @@ class ChatBackground(TelegramObject):
|
|||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["type"] = de_json_wo(data.get("type"), BackgroundType, bot)
|
||||
data["type"] = BackgroundType.de_json(data["type"], bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
|
|
@ -26,7 +26,7 @@ from telegram._chat import Chat
|
|||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils import enum
|
||||
from telegram._utils.argumentparsing import de_json_wo, parse_sequence_arg
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg
|
||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
|
@ -124,7 +124,7 @@ class ChatBoostSource(TelegramObject):
|
|||
return _class_mapping[data.pop("source")].de_json(data=data, bot=bot)
|
||||
|
||||
if "user" in data:
|
||||
data["user"] = de_json_wo(data.get("user"), User, bot)
|
||||
data["user"] = User.de_json(data["user"], bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
@ -289,7 +289,7 @@ class ChatBoost(TelegramObject):
|
|||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["source"] = de_json_wo(data.get("source"), ChatBoostSource, bot)
|
||||
data["source"] = ChatBoostSource.de_json(data["source"], bot)
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
data["add_date"] = from_timestamp(data["add_date"], tzinfo=loc_tzinfo)
|
||||
data["expiration_date"] = from_timestamp(data["expiration_date"], tzinfo=loc_tzinfo)
|
||||
|
@ -336,8 +336,8 @@ class ChatBoostUpdated(TelegramObject):
|
|||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["chat"] = de_json_wo(data.get("chat"), Chat, bot)
|
||||
data["boost"] = de_json_wo(data.get("boost"), ChatBoost, bot)
|
||||
data["chat"] = Chat.de_json(data["chat"], bot)
|
||||
data["boost"] = ChatBoost.de_json(data["boost"], bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
@ -390,8 +390,8 @@ class ChatBoostRemoved(TelegramObject):
|
|||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["chat"] = de_json_wo(data.get("chat"), Chat, bot)
|
||||
data["source"] = de_json_wo(data.get("source"), ChatBoostSource, bot)
|
||||
data["chat"] = Chat.de_json(data["chat"], bot)
|
||||
data["source"] = ChatBoostSource.de_json(data["source"], bot)
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
data["remove_date"] = from_timestamp(data["remove_date"], tzinfo=loc_tzinfo)
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ from typing import TYPE_CHECKING, Optional
|
|||
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import de_json_wo
|
||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
|
@ -185,7 +184,7 @@ class ChatInviteLink(TelegramObject):
|
|||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["creator"] = de_json_wo(data.get("creator"), User, bot)
|
||||
data["creator"] = User.de_json(data["creator"], bot)
|
||||
data["expire_date"] = from_timestamp(data.get("expire_date", None), tzinfo=loc_tzinfo)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
|
|
@ -137,7 +137,7 @@ class ChatJoinRequest(TelegramObject):
|
|||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["chat"] = de_json_wo(data.get("chat"), Chat, bot)
|
||||
data["chat"] = Chat.de_json(data["chat"], bot)
|
||||
data["from_user"] = de_json_wo(data.pop("from", None), User, bot)
|
||||
data["date"] = from_timestamp(data.get("date", None), tzinfo=loc_tzinfo)
|
||||
data["invite_link"] = de_json_wo(data.get("invite_link"), ChatInviteLink, bot)
|
||||
|
|
|
@ -23,7 +23,6 @@ from typing import TYPE_CHECKING, Final, Optional
|
|||
from telegram import constants
|
||||
from telegram._files.location import Location
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.argumentparsing import de_json_wo
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -73,7 +72,7 @@ class ChatLocation(TelegramObject):
|
|||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["location"] = de_json_wo(data.get("location"), Location, bot)
|
||||
data["location"] = Location.de_json(data["location"], bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ from typing import TYPE_CHECKING, Final, Optional
|
|||
from telegram import constants
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import de_json_wo
|
||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
|
@ -122,7 +121,7 @@ class ChatMember(TelegramObject):
|
|||
if cls is ChatMember and data.get("status") in _class_mapping:
|
||||
return _class_mapping[data.pop("status")].de_json(data=data, bot=bot)
|
||||
|
||||
data["user"] = de_json_wo(data.get("user"), User, bot)
|
||||
data["user"] = User.de_json(data["user"], bot)
|
||||
if "until_date" in data:
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
|
|
@ -149,11 +149,11 @@ class ChatMemberUpdated(TelegramObject):
|
|||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["chat"] = de_json_wo(data.get("chat"), Chat, bot)
|
||||
data["chat"] = Chat.de_json(data["chat"], bot)
|
||||
data["from_user"] = de_json_wo(data.pop("from", None), User, bot)
|
||||
data["date"] = from_timestamp(data.get("date"), tzinfo=loc_tzinfo)
|
||||
data["old_chat_member"] = de_json_wo(data.get("old_chat_member"), ChatMember, bot)
|
||||
data["new_chat_member"] = de_json_wo(data.get("new_chat_member"), ChatMember, bot)
|
||||
data["old_chat_member"] = ChatMember.de_json(data["old_chat_member"], bot)
|
||||
data["new_chat_member"] = ChatMember.de_json(data["new_chat_member"], bot)
|
||||
data["invite_link"] = de_json_wo(data.get("invite_link"), ChatInviteLink, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
|
|
@ -22,7 +22,6 @@ from typing import TYPE_CHECKING, Optional
|
|||
|
||||
from telegram._files.location import Location
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.argumentparsing import de_json_wo
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -108,6 +107,6 @@ class Venue(TelegramObject):
|
|||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["location"] = de_json_wo(data.get("location"), Location, bot)
|
||||
data["location"] = Location.de_json(data["location"], bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
|
|
@ -22,7 +22,6 @@ from typing import TYPE_CHECKING, Optional
|
|||
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import de_json_wo
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -66,6 +65,6 @@ class GameHighScore(TelegramObject):
|
|||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["user"] = de_json_wo(data.get("user"), User, bot)
|
||||
data["user"] = User.de_json(data["user"], bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
|
|
@ -23,7 +23,7 @@ from typing import TYPE_CHECKING, Optional
|
|||
|
||||
from telegram._files.sticker import Sticker
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.argumentparsing import de_json_wo, parse_sequence_arg
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -86,7 +86,7 @@ class Gift(TelegramObject):
|
|||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["sticker"] = de_json_wo(data.get("sticker"), Sticker, bot)
|
||||
data["sticker"] = Sticker.de_json(data["sticker"], bot)
|
||||
return cls(**data)
|
||||
|
||||
|
||||
|
|
|
@ -301,7 +301,7 @@ class GiveawayWinners(TelegramObject):
|
|||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["chat"] = de_json_wo(data.get("chat"), Chat, bot)
|
||||
data["chat"] = Chat.de_json(data["chat"], bot)
|
||||
data["winners"] = User.de_list(data["winners"], bot)
|
||||
data["winners_selection_date"] = from_timestamp(
|
||||
data.get("winners_selection_date"), tzinfo=loc_tzinfo
|
||||
|
|
|
@ -22,7 +22,6 @@ from typing import TYPE_CHECKING, Final, Optional
|
|||
from telegram import constants
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils import enum
|
||||
from telegram._utils.argumentparsing import de_json_wo
|
||||
from telegram._utils.types import JSONDict
|
||||
from telegram._webappinfo import WebAppInfo
|
||||
|
||||
|
@ -169,7 +168,7 @@ class MenuButtonWebApp(MenuButton):
|
|||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["web_app"] = de_json_wo(data.get("web_app"), WebAppInfo, bot)
|
||||
data["web_app"] = WebAppInfo.de_json(data["web_app"], bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot) # type: ignore[return-value]
|
||||
|
||||
|
|
|
@ -205,7 +205,7 @@ class MaybeInaccessibleMessage(TelegramObject):
|
|||
else:
|
||||
data["date"] = from_timestamp(data["date"], tzinfo=loc_tzinfo)
|
||||
|
||||
data["chat"] = de_json_wo(data.get("chat"), Chat, bot)
|
||||
data["chat"] = Chat.de_json(data["chat"], bot)
|
||||
return super()._de_json(data=data, bot=bot, api_kwargs=api_kwargs)
|
||||
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ from telegram._chat import Chat
|
|||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils import enum
|
||||
from telegram._utils.argumentparsing import de_json_wo
|
||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
|
@ -114,13 +113,13 @@ class MessageOrigin(TelegramObject):
|
|||
data["date"] = from_timestamp(data.get("date"), tzinfo=loc_tzinfo)
|
||||
|
||||
if "sender_user" in data:
|
||||
data["sender_user"] = de_json_wo(data.get("sender_user"), User, bot)
|
||||
data["sender_user"] = User.de_json(data["sender_user"], bot)
|
||||
|
||||
if "sender_chat" in data:
|
||||
data["sender_chat"] = de_json_wo(data.get("sender_chat"), Chat, bot)
|
||||
data["sender_chat"] = Chat.de_json(data["sender_chat"], bot)
|
||||
|
||||
if "chat" in data:
|
||||
data["chat"] = de_json_wo(data.get("chat"), Chat, bot)
|
||||
data["chat"] = Chat.de_json(data["chat"], bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ class MessageReactionCountUpdated(TelegramObject):
|
|||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["date"] = from_timestamp(data.get("date"), tzinfo=loc_tzinfo)
|
||||
data["chat"] = de_json_wo(data.get("chat"), Chat, bot)
|
||||
data["chat"] = Chat.de_json(data["chat"], bot)
|
||||
data["reactions"] = ReactionCount.de_list(data["reactions"], bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
@ -190,7 +190,7 @@ class MessageReactionUpdated(TelegramObject):
|
|||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["date"] = from_timestamp(data.get("date"), tzinfo=loc_tzinfo)
|
||||
data["chat"] = de_json_wo(data.get("chat"), Chat, bot)
|
||||
data["chat"] = Chat.de_json(data["chat"], bot)
|
||||
data["old_reaction"] = ReactionType.de_list(data["old_reaction"], bot)
|
||||
data["new_reaction"] = ReactionType.de_list(data["new_reaction"], bot)
|
||||
data["user"] = de_json_wo(data.get("user"), User, bot)
|
||||
|
|
|
@ -27,7 +27,7 @@ from telegram._files.video import Video
|
|||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils import enum
|
||||
from telegram._utils.argumentparsing import de_json_wo, parse_sequence_arg
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -221,7 +221,7 @@ class PaidMediaVideo(PaidMedia):
|
|||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "PaidMediaVideo":
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["video"] = de_json_wo(data.get("video"), Video, bot)
|
||||
data["video"] = Video.de_json(data["video"], bot)
|
||||
return super().de_json(data=data, bot=bot) # type: ignore[return-value]
|
||||
|
||||
|
||||
|
|
|
@ -238,7 +238,7 @@ class Credentials(TelegramObject):
|
|||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["secure_data"] = de_json_wo(data.get("secure_data"), SecureData, bot)
|
||||
data["secure_data"] = SecureData.de_json(data["secure_data"], bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ from typing import TYPE_CHECKING, Optional
|
|||
from telegram._passport.credentials import EncryptedCredentials
|
||||
from telegram._passport.encryptedpassportelement import EncryptedPassportElement
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.argumentparsing import de_json_wo, parse_sequence_arg
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -87,7 +87,7 @@ class PassportData(TelegramObject):
|
|||
data = cls._parse_data(data)
|
||||
|
||||
data["data"] = EncryptedPassportElement.de_list(data["data"], bot)
|
||||
data["credentials"] = de_json_wo(data.get("credentials"), EncryptedCredentials, bot)
|
||||
data["credentials"] = EncryptedCredentials.de_json(data["credentials"], bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ class ShippingQuery(TelegramObject):
|
|||
data = cls._parse_data(data)
|
||||
|
||||
data["from_user"] = de_json_wo(data.pop("from", None), User, bot)
|
||||
data["shipping_address"] = de_json_wo(data.get("shipping_address"), ShippingAddress, bot)
|
||||
data["shipping_address"] = ShippingAddress.de_json(data["shipping_address"], bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
|
|
@ -311,7 +311,7 @@ class TransactionPartnerUser(TransactionPartner):
|
|||
"""See :meth:`telegram.TransactionPartner.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["user"] = de_json_wo(data.get("user"), User, bot)
|
||||
data["user"] = User.de_json(data["user"], bot)
|
||||
data["affiliate"] = de_json_wo(data.get("affiliate"), AffiliateInfo, bot)
|
||||
data["paid_media"] = de_list_wo(data.get("paid_media"), PaidMedia, bot)
|
||||
data["subscription_period"] = (
|
||||
|
|
|
@ -21,7 +21,6 @@ from typing import TYPE_CHECKING, Optional
|
|||
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import de_json_wo
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -72,7 +71,7 @@ class ProximityAlertTriggered(TelegramObject):
|
|||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["traveler"] = de_json_wo(data.get("traveler"), User, bot)
|
||||
data["watcher"] = de_json_wo(data.get("watcher"), User, bot)
|
||||
data["traveler"] = User.de_json(data["traveler"], bot)
|
||||
data["watcher"] = User.de_json(data["watcher"], bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
|
|
@ -23,7 +23,6 @@ from typing import TYPE_CHECKING, Final, Literal, Optional, Union
|
|||
from telegram import constants
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils import enum
|
||||
from telegram._utils.argumentparsing import de_json_wo
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -227,6 +226,6 @@ class ReactionCount(TelegramObject):
|
|||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["type"] = de_json_wo(data.get("type"), ReactionType, bot)
|
||||
data["type"] = ReactionType.de_json(data["type"], bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
|
|
@ -252,7 +252,7 @@ class ExternalReplyInfo(TelegramObject):
|
|||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["origin"] = de_json_wo(data.get("origin"), MessageOrigin, bot)
|
||||
data["origin"] = MessageOrigin.de_json(data["origin"], bot)
|
||||
data["chat"] = de_json_wo(data.get("chat"), Chat, bot)
|
||||
data["link_preview_options"] = de_json_wo(
|
||||
data.get("link_preview_options"), LinkPreviewOptions, bot
|
||||
|
|
Loading…
Add table
Reference in a new issue