Explicit Type Annotations (#3508)

This commit is contained in:
Bibo-Joshi 2023-02-02 18:55:07 +01:00 committed by GitHub
parent 1701950a1d
commit 23d0bd8fe3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
137 changed files with 1353 additions and 1168 deletions

61
.github/workflows/type_completeness.yml vendored Normal file
View file

@ -0,0 +1,61 @@
name: Check Type Completeness
on:
pull_request:
branches:
- master
push:
branches:
- master
jobs:
test-type-completeness:
name: test-type-completeness
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: git fetch --depth=1 # https://github.com/actions/checkout/issues/329#issuecomment-674881489
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: 3.9
cache: 'pip'
cache-dependency-path: '**/requirements*.txt'
- name: Install Pyright
run: |
python -W ignore -m pip install pyright~=1.1.291
- name: Get Base Completeness
run: |
git checkout ${{ github.base_ref }}
pip install . -U
pyright --verifytypes telegram --ignoreexternal --outputjson > base.json || true
- name: Get PR Completeness
run: |
git checkout ${{ github.head_ref }}
pip install . -U
pyright --verifytypes telegram --ignoreexternal --outputjson > pr.json || true
- name: Compare Completeness
uses: jannekem/run-python-script-action@v1
with:
script: |
import json
import os
base = float(
json.load(open("base.json", "rb"))["typeCompleteness"]["completenessScore"]
)
pr = float(
json.load(open("pr.json", "rb"))["typeCompleteness"]["completenessScore"]
)
if pr < (base - 0.1):
text = f"This PR decreases type completeness by {round(base - pr, 3)} ❌"
set_summary(text)
error(text)
exit(1)
elif pr > (base + 0.1):
text = f"This PR increases type completeness by {round(pr - base, 3)} ✨"
set_summary(text)
print(text)
else:
text = f"This PR does not change type completeness by more than 0.1 ✅"
set_summary(text)
print(text)

View file

@ -565,6 +565,11 @@ def autodoc_process_bases(app, name, obj, option, bases: list):
# let's use a string representation of the object
base = str(base)
# Special case for abstract context managers which are wrongly resoled for some reason
if base.startswith("typing.AbstractAsyncContextManager"):
bases[idx] = ":class:`contextlib.AbstractAsyncContextManager`"
continue
# Special case because base classes are in std lib:
if "StringEnum" in base == "<enum 'StringEnum'>":
bases[idx] = ":class:`enum.Enum`"

View file

@ -5,7 +5,7 @@ telegram.ext.filters Module
The classes in `filters.py` are sorted alphabetically such that :bysource: still is readable
.. automodule:: telegram.ext.filters
:inherited-members:
:inherited-members: BaseFilter, MessageFilter, UpdateFilter
:members:
:show-inheritance:
:member-order: bysource
:member-order: bysource

View file

@ -343,7 +343,7 @@ from ._writeaccessallowed import WriteAccessAllowed
#: :obj:`str`: The version of the `python-telegram-bot` library as string.
#: To get detailed information about the version number, please use :data:`__version_info__`
#: instead.
__version__ = _version.__version__
__version__: str = _version.__version__
#: :class:`typing.NamedTuple`: A tuple containing the five components of the version number:
#: `major`, `minor`, `micro`, `releaselevel`, and `serial`.
#: All values except `releaselevel` are integers.
@ -352,13 +352,13 @@ __version__ = _version.__version__
#: ``__version_info__.major`` and so on.
#:
#: .. versionadded:: 20.0
__version_info__ = _version.__version_info__
__version_info__: _version.Version = _version.__version_info__
#: :obj:`str`: Shortcut for :const:`telegram.constants.BOT_API_VERSION`.
#:
#: .. versionchanged:: 20.0
#: This constant was previously named ``bot_api_version``.
__bot_api_version__ = _version.__bot_api_version__
__bot_api_version__: str = _version.__bot_api_version__
#: :class:`typing.NamedTuple`: Shortcut for :const:`telegram.constants.BOT_API_VERSION_INFO`.
#:
#: .. versionadded:: 20.0
__bot_api_version_info__ = _version.__bot_api_version_info__
__bot_api_version_info__: constants._BotAPIVersion = _version.__bot_api_version_info__

View file

@ -36,6 +36,7 @@ def _git_revision() -> Optional[str]:
def print_ver_info() -> None: # skipcq: PY-D0003
"""Prints version information for python-telegram-bot, the Bot API and Python."""
git_revision = _git_revision()
print(f"python-telegram-bot {telegram_ver}" + (f" ({git_revision})" if git_revision else ""))
print(f"Bot API {BOT_API_VERSION}")
@ -44,6 +45,7 @@ def print_ver_info() -> None: # skipcq: PY-D0003
def main() -> None: # skipcq: PY-D0003
"""Prints version information for python-telegram-bot, the Bot API and Python."""
print_ver_info()

View file

@ -23,12 +23,12 @@ import copy
import functools
import logging
import pickle
from contextlib import AbstractAsyncContextManager
from datetime import datetime
from types import TracebackType
from typing import (
TYPE_CHECKING,
Any,
AsyncContextManager,
Callable,
Dict,
List,
@ -114,7 +114,7 @@ if TYPE_CHECKING:
BT = TypeVar("BT", bound="Bot")
class Bot(TelegramObject, AbstractAsyncContextManager):
class Bot(TelegramObject, AsyncContextManager["Bot"]):
"""This object represents a Telegram Bot.
Instances of this class can be used as asyncio context managers, where
@ -229,13 +229,13 @@ class Bot(TelegramObject, AbstractAsyncContextManager):
super().__init__(api_kwargs=None)
if not token:
raise InvalidToken("You must pass the token you received from https://t.me/Botfather!")
self._token = token
self._token: str = token
self._base_url = base_url + self._token
self._base_file_url = base_file_url + self._token
self._local_mode = local_mode
self._base_url: str = base_url + self._token
self._base_file_url: str = base_file_url + self._token
self._local_mode: bool = local_mode
self._bot_user: Optional[User] = None
self._private_key = None
self._private_key: Optional[bytes] = None
self._logger = logging.getLogger(__name__)
self._initialized = False
@ -312,7 +312,7 @@ class Bot(TelegramObject, AbstractAsyncContextManager):
"""
raise pickle.PicklingError("Bot objects cannot be pickled!")
def __deepcopy__(self, memodict: dict) -> NoReturn:
def __deepcopy__(self, memodict: Dict[int, object]) -> NoReturn:
"""Customizes how :func:`copy.deepcopy` processes objects of this type. Bots can not
be deepcopied and this method will always raise an exception.

View file

@ -54,8 +54,8 @@ class BotCommand(TelegramObject):
def __init__(self, command: str, description: str, *, api_kwargs: JSONDict = None):
super().__init__(api_kwargs=api_kwargs)
self.command = command
self.description = description
self.command: str = command
self.description: str = description
self._id_attrs = (self.command, self.description)

View file

@ -77,7 +77,7 @@ class BotCommandScope(TelegramObject):
def __init__(self, type: str, *, api_kwargs: JSONDict = None):
super().__init__(api_kwargs=api_kwargs)
self.type = type
self.type: str = type
self._id_attrs = (self.type,)
self._freeze()
@ -200,7 +200,7 @@ class BotCommandScopeChat(BotCommandScope):
def __init__(self, chat_id: Union[str, int], *, api_kwargs: JSONDict = None):
super().__init__(type=BotCommandScope.CHAT, api_kwargs=api_kwargs)
with self._unfrozen():
self.chat_id = (
self.chat_id: Union[str, int] = (
chat_id if isinstance(chat_id, str) and chat_id.startswith("@") else int(chat_id)
)
self._id_attrs = (self.type, self.chat_id)
@ -227,7 +227,7 @@ class BotCommandScopeChatAdministrators(BotCommandScope):
def __init__(self, chat_id: Union[str, int], *, api_kwargs: JSONDict = None):
super().__init__(type=BotCommandScope.CHAT_ADMINISTRATORS, api_kwargs=api_kwargs)
with self._unfrozen():
self.chat_id = (
self.chat_id: Union[str, int] = (
chat_id if isinstance(chat_id, str) and chat_id.startswith("@") else int(chat_id)
)
self._id_attrs = (self.type, self.chat_id)
@ -257,8 +257,8 @@ class BotCommandScopeChatMember(BotCommandScope):
def __init__(self, chat_id: Union[str, int], user_id: int, *, api_kwargs: JSONDict = None):
super().__init__(type=BotCommandScope.CHAT_MEMBER, api_kwargs=api_kwargs)
with self._unfrozen():
self.chat_id = (
self.chat_id: Union[str, int] = (
chat_id if isinstance(chat_id, str) and chat_id.startswith("@") else int(chat_id)
)
self.user_id = user_id
self.user_id: int = user_id
self._id_attrs = (self.type, self.chat_id, self.user_id)

View file

@ -127,14 +127,14 @@ class CallbackQuery(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.id = id # pylint: disable=invalid-name
self.from_user = from_user
self.chat_instance = chat_instance
self.id: str = id # pylint: disable=invalid-name
self.from_user: User = from_user
self.chat_instance: str = chat_instance
# Optionals
self.message = message
self.data = data
self.inline_message_id = inline_message_id
self.game_short_name = game_short_name
self.message: Optional[Message] = message
self.data: Optional[str] = data
self.inline_message_id: Optional[str] = inline_message_id
self.game_short_name: Optional[str] = game_short_name
self._id_attrs = (self.id,)

View file

@ -352,37 +352,39 @@ class Chat(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.id = id # pylint: disable=invalid-name
self.type = enum.get_member(constants.ChatType, type, type)
self.id: int = id # pylint: disable=invalid-name
self.type: str = enum.get_member(constants.ChatType, type, type)
# Optionals
self.title = title
self.username = username
self.first_name = first_name
self.last_name = last_name
self.photo = photo
self.bio = bio
self.has_private_forwards = has_private_forwards
self.description = description
self.invite_link = invite_link
self.pinned_message = pinned_message
self.permissions = permissions
self.slow_mode_delay = slow_mode_delay
self.message_auto_delete_time = (
self.title: Optional[str] = title
self.username: Optional[str] = username
self.first_name: Optional[str] = first_name
self.last_name: Optional[str] = last_name
self.photo: Optional[ChatPhoto] = photo
self.bio: Optional[str] = bio
self.has_private_forwards: Optional[bool] = has_private_forwards
self.description: Optional[str] = description
self.invite_link: Optional[str] = invite_link
self.pinned_message: Optional[Message] = pinned_message
self.permissions: Optional[ChatPermissions] = permissions
self.slow_mode_delay: Optional[int] = slow_mode_delay
self.message_auto_delete_time: Optional[int] = (
int(message_auto_delete_time) if message_auto_delete_time is not None else None
)
self.has_protected_content = has_protected_content
self.sticker_set_name = sticker_set_name
self.can_set_sticker_set = can_set_sticker_set
self.linked_chat_id = linked_chat_id
self.location = location
self.join_to_send_messages = join_to_send_messages
self.join_by_request = join_by_request
self.has_restricted_voice_and_video_messages = has_restricted_voice_and_video_messages
self.is_forum = is_forum
self.active_usernames = parse_sequence_arg(active_usernames)
self.emoji_status_custom_emoji_id = emoji_status_custom_emoji_id
self.has_aggressive_anti_spam_enabled = has_aggressive_anti_spam_enabled
self.has_hidden_members = has_hidden_members
self.has_protected_content: Optional[bool] = has_protected_content
self.sticker_set_name: Optional[str] = sticker_set_name
self.can_set_sticker_set: Optional[bool] = can_set_sticker_set
self.linked_chat_id: Optional[int] = linked_chat_id
self.location: Optional[ChatLocation] = location
self.join_to_send_messages: Optional[bool] = join_to_send_messages
self.join_by_request: Optional[bool] = join_by_request
self.has_restricted_voice_and_video_messages: Optional[
bool
] = has_restricted_voice_and_video_messages
self.is_forum: Optional[bool] = is_forum
self.active_usernames: Tuple[str, ...] = parse_sequence_arg(active_usernames)
self.emoji_status_custom_emoji_id: Optional[str] = emoji_status_custom_emoji_id
self.has_aggressive_anti_spam_enabled: Optional[bool] = has_aggressive_anti_spam_enabled
self.has_hidden_members: Optional[bool] = has_hidden_members
self._id_attrs = (self.id,)

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the class which represents a Telegram ChatAdministratorRights."""
from typing import Optional
from telegram._telegramobject import TelegramObject
from telegram._utils.types import JSONDict
@ -138,19 +139,19 @@ class ChatAdministratorRights(TelegramObject):
) -> None:
super().__init__(api_kwargs=api_kwargs)
# Required
self.is_anonymous = is_anonymous
self.can_manage_chat = can_manage_chat
self.can_delete_messages = can_delete_messages
self.can_manage_video_chats = can_manage_video_chats
self.can_restrict_members = can_restrict_members
self.can_promote_members = can_promote_members
self.can_change_info = can_change_info
self.can_invite_users = can_invite_users
self.is_anonymous: bool = is_anonymous
self.can_manage_chat: bool = can_manage_chat
self.can_delete_messages: bool = can_delete_messages
self.can_manage_video_chats: bool = can_manage_video_chats
self.can_restrict_members: bool = can_restrict_members
self.can_promote_members: bool = can_promote_members
self.can_change_info: bool = can_change_info
self.can_invite_users: bool = can_invite_users
# Optionals
self.can_post_messages = can_post_messages
self.can_edit_messages = can_edit_messages
self.can_pin_messages = can_pin_messages
self.can_manage_topics = can_manage_topics
self.can_post_messages: Optional[bool] = can_post_messages
self.can_edit_messages: Optional[bool] = can_edit_messages
self.can_pin_messages: Optional[bool] = can_pin_messages
self.can_manage_topics: Optional[bool] = can_manage_topics
self._id_attrs = (
self.is_anonymous,

View file

@ -121,17 +121,17 @@ class ChatInviteLink(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.invite_link = invite_link
self.creator = creator
self.creates_join_request = creates_join_request
self.is_primary = is_primary
self.is_revoked = is_revoked
self.invite_link: str = invite_link
self.creator: User = creator
self.creates_join_request: bool = creates_join_request
self.is_primary: bool = is_primary
self.is_revoked: bool = is_revoked
# Optionals
self.expire_date = expire_date
self.member_limit = member_limit
self.name = name
self.pending_join_request_count = (
self.expire_date: Optional[datetime.datetime] = expire_date
self.member_limit: Optional[int] = member_limit
self.name: Optional[str] = name
self.pending_join_request_count: Optional[int] = (
int(pending_join_request_count) if pending_join_request_count is not None else None
)
self._id_attrs = (

View file

@ -78,13 +78,13 @@ class ChatJoinRequest(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.chat = chat
self.from_user = from_user
self.date = date
self.chat: Chat = chat
self.from_user: User = from_user
self.date: datetime.datetime = date
# Optionals
self.bio = bio
self.invite_link = invite_link
self.bio: Optional[str] = bio
self.invite_link: Optional[ChatInviteLink] = invite_link
self._id_attrs = (self.chat, self.from_user, self.date)

View file

@ -60,8 +60,8 @@ class ChatLocation(TelegramObject):
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.location = location
self.address = address
self.location: Location = location
self.address: str = address
self._id_attrs = (self.location,)

View file

@ -96,8 +96,8 @@ class ChatMember(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required by all subclasses
self.user = user
self.status = status
self.user: User = user
self.status: str = status
self._id_attrs = (self.user, self.status)
@ -165,8 +165,8 @@ class ChatMemberOwner(ChatMember):
):
super().__init__(status=ChatMember.OWNER, user=user, api_kwargs=api_kwargs)
with self._unfrozen():
self.is_anonymous = is_anonymous
self.custom_title = custom_title
self.is_anonymous: bool = is_anonymous
self.custom_title: Optional[str] = custom_title
class ChatMemberAdministrator(ChatMember):
@ -302,20 +302,20 @@ class ChatMemberAdministrator(ChatMember):
):
super().__init__(status=ChatMember.ADMINISTRATOR, user=user, api_kwargs=api_kwargs)
with self._unfrozen():
self.can_be_edited = can_be_edited
self.is_anonymous = is_anonymous
self.can_manage_chat = can_manage_chat
self.can_delete_messages = can_delete_messages
self.can_manage_video_chats = can_manage_video_chats
self.can_restrict_members = can_restrict_members
self.can_promote_members = can_promote_members
self.can_change_info = can_change_info
self.can_invite_users = can_invite_users
self.can_post_messages = can_post_messages
self.can_edit_messages = can_edit_messages
self.can_pin_messages = can_pin_messages
self.can_manage_topics = can_manage_topics
self.custom_title = custom_title
self.can_be_edited: bool = can_be_edited
self.is_anonymous: bool = is_anonymous
self.can_manage_chat: bool = can_manage_chat
self.can_delete_messages: bool = can_delete_messages
self.can_manage_video_chats: bool = can_manage_video_chats
self.can_restrict_members: bool = can_restrict_members
self.can_promote_members: bool = can_promote_members
self.can_change_info: bool = can_change_info
self.can_invite_users: bool = can_invite_users
self.can_post_messages: Optional[bool] = can_post_messages
self.can_edit_messages: Optional[bool] = can_edit_messages
self.can_pin_messages: Optional[bool] = can_pin_messages
self.can_manage_topics: Optional[bool] = can_manage_topics
self.custom_title: Optional[str] = custom_title
class ChatMemberMember(ChatMember):
@ -448,17 +448,17 @@ class ChatMemberRestricted(ChatMember):
):
super().__init__(status=ChatMember.RESTRICTED, user=user, api_kwargs=api_kwargs)
with self._unfrozen():
self.is_member = is_member
self.can_change_info = can_change_info
self.can_invite_users = can_invite_users
self.can_pin_messages = can_pin_messages
self.can_send_messages = can_send_messages
self.can_send_media_messages = can_send_media_messages
self.can_send_polls = can_send_polls
self.can_send_other_messages = can_send_other_messages
self.can_add_web_page_previews = can_add_web_page_previews
self.can_manage_topics = can_manage_topics
self.until_date = until_date
self.is_member: bool = is_member
self.can_change_info: bool = can_change_info
self.can_invite_users: bool = can_invite_users
self.can_pin_messages: bool = can_pin_messages
self.can_send_messages: bool = can_send_messages
self.can_send_media_messages: bool = can_send_media_messages
self.can_send_polls: bool = can_send_polls
self.can_send_other_messages: bool = can_send_other_messages
self.can_add_web_page_previews: bool = can_add_web_page_previews
self.can_manage_topics: bool = can_manage_topics
self.until_date: datetime.datetime = until_date
class ChatMemberLeft(ChatMember):
@ -521,4 +521,4 @@ class ChatMemberBanned(ChatMember):
):
super().__init__(status=ChatMember.BANNED, user=user, api_kwargs=api_kwargs)
with self._unfrozen():
self.until_date = until_date
self.until_date: datetime.datetime = until_date

View file

@ -91,14 +91,14 @@ class ChatMemberUpdated(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.chat = chat
self.from_user = from_user
self.date = date
self.old_chat_member = old_chat_member
self.new_chat_member = new_chat_member
self.chat: Chat = chat
self.from_user: User = from_user
self.date: datetime.datetime = date
self.old_chat_member: ChatMember = old_chat_member
self.new_chat_member: ChatMember = new_chat_member
# Optionals
self.invite_link = invite_link
self.invite_link: Optional[ChatInviteLink] = invite_link
self._id_attrs = (
self.chat,

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram ChatPermission."""
from typing import Optional
from telegram._telegramobject import TelegramObject
from telegram._utils.types import JSONDict
@ -120,15 +121,15 @@ class ChatPermissions(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.can_send_messages = can_send_messages
self.can_send_media_messages = can_send_media_messages
self.can_send_polls = can_send_polls
self.can_send_other_messages = can_send_other_messages
self.can_add_web_page_previews = can_add_web_page_previews
self.can_change_info = can_change_info
self.can_invite_users = can_invite_users
self.can_pin_messages = can_pin_messages
self.can_manage_topics = can_manage_topics
self.can_send_messages: Optional[bool] = can_send_messages
self.can_send_media_messages: Optional[bool] = can_send_media_messages
self.can_send_polls: Optional[bool] = can_send_polls
self.can_send_other_messages: Optional[bool] = can_send_other_messages
self.can_add_web_page_previews: Optional[bool] = can_add_web_page_previews
self.can_change_info: Optional[bool] = can_change_info
self.can_invite_users: Optional[bool] = can_invite_users
self.can_pin_messages: Optional[bool] = can_pin_messages
self.can_manage_topics: Optional[bool] = can_manage_topics
self._id_attrs = (
self.can_send_messages,

View file

@ -80,12 +80,12 @@ class ChosenInlineResult(TelegramObject):
super().__init__(api_kwargs=api_kwargs)
# Required
self.result_id = result_id
self.from_user = from_user
self.query = query
self.result_id: str = result_id
self.from_user: User = from_user
self.query: str = query
# Optionals
self.location = location
self.inline_message_id = inline_message_id
self.location: Optional[Location] = location
self.inline_message_id: Optional[str] = inline_message_id
self._id_attrs = (self.result_id,)

View file

@ -91,8 +91,8 @@ class Dice(TelegramObject):
def __init__(self, value: int, emoji: str, *, api_kwargs: JSONDict = None):
super().__init__(api_kwargs=api_kwargs)
self.value = value
self.emoji = emoji
self.value: int = value
self.emoji: str = emoji
self._id_attrs = (self.value, self.emoji)

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""Common base class for media objects"""
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional
from telegram._telegramobject import TelegramObject
from telegram._utils.defaultvalue import DEFAULT_NONE
@ -64,9 +64,9 @@ class _BaseMedium(TelegramObject):
# Required
self.file_id: str = str(file_id)
self.file_unique_id = str(file_unique_id)
self.file_unique_id: str = str(file_unique_id)
# Optionals
self.file_size = file_size
self.file_size: Optional[int] = file_size
self._id_attrs = (self.file_unique_id,)

View file

@ -74,7 +74,7 @@ class _BaseThumbedMedium(_BaseMedium):
file_size=file_size,
api_kwargs=api_kwargs,
)
self.thumb = thumb
self.thumb: Optional[PhotoSize] = thumb
@classmethod
def de_json(

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram Animation."""
from typing import Optional
from telegram._files._basethumbedmedium import _BaseThumbedMedium
from telegram._files.photosize import PhotoSize
@ -85,9 +86,9 @@ class Animation(_BaseThumbedMedium):
)
with self._unfrozen():
# Required
self.width = width
self.height = height
self.duration = duration
self.width: int = width
self.height: int = height
self.duration: int = duration
# Optional
self.mime_type = mime_type
self.file_name = file_name
self.mime_type: Optional[str] = mime_type
self.file_name: Optional[str] = file_name

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram Audio."""
from typing import Optional
from telegram._files._basethumbedmedium import _BaseThumbedMedium
from telegram._files.photosize import PhotoSize
@ -88,9 +89,9 @@ class Audio(_BaseThumbedMedium):
)
with self._unfrozen():
# Required
self.duration = duration
self.duration: int = duration
# Optional
self.performer = performer
self.title = title
self.mime_type = mime_type
self.file_name = file_name
self.performer: Optional[str] = performer
self.title: Optional[str] = title
self.mime_type: Optional[str] = mime_type
self.file_name: Optional[str] = file_name

View file

@ -90,10 +90,10 @@ class ChatPhoto(TelegramObject):
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.small_file_id = small_file_id
self.small_file_unique_id = small_file_unique_id
self.big_file_id = big_file_id
self.big_file_unique_id = big_file_unique_id
self.small_file_id: str = small_file_id
self.small_file_unique_id: str = small_file_unique_id
self.big_file_id: str = big_file_id
self.big_file_unique_id: str = big_file_unique_id
self._id_attrs = (
self.small_file_unique_id,

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram Contact."""
from typing import Optional
from telegram._telegramobject import TelegramObject
from telegram._utils.types import JSONDict
@ -58,12 +59,12 @@ class Contact(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.phone_number = str(phone_number)
self.first_name = first_name
self.phone_number: str = str(phone_number)
self.first_name: str = first_name
# Optionals
self.last_name = last_name
self.user_id = user_id
self.vcard = vcard
self.last_name: Optional[str] = last_name
self.user_id: Optional[int] = user_id
self.vcard: Optional[str] = vcard
self._id_attrs = (self.phone_number,)

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram Document."""
from typing import Optional
from telegram._files._basethumbedmedium import _BaseThumbedMedium
from telegram._files.photosize import PhotoSize
@ -74,5 +75,5 @@ class Document(_BaseThumbedMedium):
)
with self._unfrozen():
# Optional
self.mime_type = mime_type
self.file_name = file_name
self.mime_type: Optional[str] = mime_type
self.file_name: Optional[str] = file_name

View file

@ -93,11 +93,11 @@ class File(TelegramObject):
super().__init__(api_kwargs=api_kwargs)
# Required
self.file_id = str(file_id)
self.file_unique_id = str(file_unique_id)
self.file_id: str = str(file_id)
self.file_unique_id: str = str(file_unique_id)
# Optionals
self.file_size = file_size
self.file_path = file_path
self.file_size: Optional[int] = file_size
self.file_path: Optional[str] = file_path
self._credentials: Optional["FileCredentials"] = None

View file

@ -71,7 +71,7 @@ class InputFile:
self, obj: Union[IO[bytes], bytes, str], filename: str = None, attach: bool = False
):
if isinstance(obj, bytes):
self.input_file_content = obj
self.input_file_content: bytes = obj
elif isinstance(obj, str):
self.input_file_content = obj.encode("utf-8")
else:
@ -81,11 +81,13 @@ class InputFile:
self.attach_name: Optional[str] = "attached" + uuid4().hex if attach else None
if filename:
self.mimetype = mimetypes.guess_type(filename, strict=False)[0] or _DEFAULT_MIME_TYPE
self.mimetype: str = (
mimetypes.guess_type(filename, strict=False)[0] or _DEFAULT_MIME_TYPE
)
else:
self.mimetype = _DEFAULT_MIME_TYPE
self.filename = filename or self.mimetype.replace("/", ".")
self.filename: str = filename or self.mimetype.replace("/", ".")
@property
def field_tuple(self) -> FieldTuple:

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""Base class for Telegram InputMedia Objects."""
from typing import Optional, Sequence, Union
from typing import Optional, Sequence, Tuple, Union
from telegram._files.animation import Animation
from telegram._files.audio import Audio
@ -94,11 +94,11 @@ class InputMedia(TelegramObject):
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.type = media_type
self.media = media
self.caption = caption
self.caption_entities = parse_sequence_arg(caption_entities)
self.parse_mode = parse_mode
self.type: str = media_type
self.media: Union[str, InputFile, Animation, Audio, Document, PhotoSize, Video] = media
self.caption: Optional[str] = caption
self.caption_entities: Tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
self.parse_mode: ODVInput[str] = parse_mode
self._freeze()
@ -214,11 +214,11 @@ class InputMediaAnimation(InputMedia):
api_kwargs=api_kwargs,
)
with self._unfrozen():
self.thumb = self._parse_thumb_input(thumb)
self.width = width
self.height = height
self.duration = duration
self.has_spoiler = has_spoiler
self.thumb: Optional[Union[str, InputFile]] = self._parse_thumb_input(thumb)
self.width: Optional[int] = width
self.height: Optional[int] = height
self.duration: Optional[int] = duration
self.has_spoiler: Optional[bool] = has_spoiler
class InputMediaPhoto(InputMedia):
@ -296,7 +296,7 @@ class InputMediaPhoto(InputMedia):
)
with self._unfrozen():
self.has_spoiler = has_spoiler
self.has_spoiler: Optional[bool] = has_spoiler
class InputMediaVideo(InputMedia):
@ -411,12 +411,12 @@ class InputMediaVideo(InputMedia):
api_kwargs=api_kwargs,
)
with self._unfrozen():
self.width = width
self.height = height
self.duration = duration
self.thumb = self._parse_thumb_input(thumb)
self.supports_streaming = supports_streaming
self.has_spoiler = has_spoiler
self.width: Optional[int] = width
self.height: Optional[int] = height
self.duration: Optional[int] = duration
self.thumb: Optional[Union[str, InputFile]] = self._parse_thumb_input(thumb)
self.supports_streaming: Optional[bool] = supports_streaming
self.has_spoiler: Optional[bool] = has_spoiler
class InputMediaAudio(InputMedia):
@ -516,10 +516,10 @@ class InputMediaAudio(InputMedia):
api_kwargs=api_kwargs,
)
with self._unfrozen():
self.thumb = self._parse_thumb_input(thumb)
self.duration = duration
self.title = title
self.performer = performer
self.thumb: Optional[Union[str, InputFile]] = self._parse_thumb_input(thumb)
self.duration: Optional[int] = duration
self.title: Optional[str] = title
self.performer: Optional[str] = performer
class InputMediaDocument(InputMedia):
@ -603,5 +603,5 @@ class InputMediaDocument(InputMedia):
api_kwargs=api_kwargs,
)
with self._unfrozen():
self.thumb = self._parse_thumb_input(thumb)
self.disable_content_type_detection = disable_content_type_detection
self.thumb: Optional[Union[str, InputFile]] = self._parse_thumb_input(thumb)
self.disable_content_type_detection: Optional[bool] = disable_content_type_detection

View file

@ -18,7 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram Location."""
from typing import ClassVar
from typing import ClassVar, Optional
from telegram import constants
from telegram._telegramobject import TelegramObject
@ -81,14 +81,14 @@ class Location(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.longitude = longitude
self.latitude = latitude
self.longitude: float = longitude
self.latitude: float = latitude
# Optionals
self.horizontal_accuracy = horizontal_accuracy
self.live_period = live_period
self.heading = heading
self.proximity_alert_radius = (
self.horizontal_accuracy: Optional[float] = horizontal_accuracy
self.live_period: Optional[int] = live_period
self.heading: Optional[int] = heading
self.proximity_alert_radius: Optional[int] = (
int(proximity_alert_radius) if proximity_alert_radius else None
)

View file

@ -71,5 +71,5 @@ class PhotoSize(_BaseMedium):
)
with self._unfrozen():
# Required
self.width = width
self.height = height
self.width: int = width
self.height: int = height

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains objects that represent stickers."""
from typing import TYPE_CHECKING, ClassVar, Optional, Sequence
from typing import TYPE_CHECKING, ClassVar, Optional, Sequence, Tuple
from telegram import constants
from telegram._files._basethumbedmedium import _BaseThumbedMedium
@ -152,17 +152,17 @@ class Sticker(_BaseThumbedMedium):
)
with self._unfrozen():
# Required
self.width = width
self.height = height
self.is_animated = is_animated
self.is_video = is_video
self.type = type
self.width: int = width
self.height: int = height
self.is_animated: bool = is_animated
self.is_video: bool = is_video
self.type: str = type
# Optional
self.emoji = emoji
self.set_name = set_name
self.mask_position = mask_position
self.premium_animation = premium_animation
self.custom_emoji_id = custom_emoji_id
self.emoji: Optional[str] = emoji
self.set_name: Optional[str] = set_name
self.mask_position: Optional[MaskPosition] = mask_position
self.premium_animation: Optional[File] = premium_animation
self.custom_emoji_id: Optional[str] = custom_emoji_id
REGULAR: ClassVar[str] = constants.StickerType.REGULAR
""":const:`telegram.constants.StickerType.REGULAR`"""
@ -265,14 +265,14 @@ class StickerSet(TelegramObject):
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.name = name
self.title = title
self.is_animated = is_animated
self.is_video = is_video
self.stickers = parse_sequence_arg(stickers)
self.sticker_type = sticker_type
self.name: str = name
self.title: str = title
self.is_animated: bool = is_animated
self.is_video: bool = is_video
self.stickers: Tuple[Sticker, ...] = parse_sequence_arg(stickers)
self.sticker_type: str = sticker_type
# Optional
self.thumb = thumb
self.thumb: Optional[PhotoSize] = thumb
self._id_attrs = (self.name,)
@ -348,10 +348,10 @@ class MaskPosition(TelegramObject):
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.point = point
self.x_shift = x_shift
self.y_shift = y_shift
self.scale = scale
self.point: str = point
self.x_shift: float = x_shift
self.y_shift: float = y_shift
self.scale: float = scale
self._id_attrs = (self.point, self.x_shift, self.y_shift, self.scale)

View file

@ -89,14 +89,14 @@ class Venue(TelegramObject):
super().__init__(api_kwargs=api_kwargs)
# Required
self.location = location
self.title = title
self.address = address
self.location: Location = location
self.title: str = title
self.address: str = address
# Optionals
self.foursquare_id = foursquare_id
self.foursquare_type = foursquare_type
self.google_place_id = google_place_id
self.google_place_type = google_place_type
self.foursquare_id: Optional[str] = foursquare_id
self.foursquare_type: Optional[str] = foursquare_type
self.google_place_id: Optional[str] = google_place_id
self.google_place_type: Optional[str] = google_place_type
self._id_attrs = (self.location, self.title)

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram Video."""
from typing import Optional
from telegram._files._basethumbedmedium import _BaseThumbedMedium
from telegram._files.photosize import PhotoSize
@ -84,9 +85,9 @@ class Video(_BaseThumbedMedium):
)
with self._unfrozen():
# Required
self.width = width
self.height = height
self.duration = duration
self.width: int = width
self.height: int = height
self.duration: int = duration
# Optional
self.mime_type = mime_type
self.file_name = file_name
self.mime_type: Optional[str] = mime_type
self.file_name: Optional[str] = file_name

View file

@ -77,5 +77,5 @@ class VideoNote(_BaseThumbedMedium):
)
with self._unfrozen():
# Required
self.length = length
self.duration = duration
self.length: int = length
self.duration: int = duration

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram Voice."""
from typing import Optional
from telegram._files._basemedium import _BaseMedium
from telegram._utils.types import JSONDict
@ -70,6 +71,6 @@ class Voice(_BaseMedium):
)
with self._unfrozen():
# Required
self.duration = duration
self.duration: int = duration
# Optional
self.mime_type = mime_type
self.mime_type: Optional[str] = mime_type

View file

@ -18,7 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram ForceReply."""
from typing import ClassVar
from typing import ClassVar, Optional
from telegram import constants
from telegram._telegramobject import TelegramObject
@ -85,9 +85,9 @@ class ForceReply(TelegramObject):
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.force_reply = True
self.selective = selective
self.input_field_placeholder = input_field_placeholder
self.force_reply: bool = True
self.selective: Optional[bool] = selective
self.input_field_placeholder: Optional[str] = input_field_placeholder
self._id_attrs = (self.selective,)

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains objects related to Telegram forum topics."""
from typing import Optional
from telegram._telegramobject import TelegramObject
from telegram._utils.types import JSONDict
@ -59,10 +60,10 @@ class ForumTopic(TelegramObject):
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.message_thread_id = message_thread_id
self.name = name
self.icon_color = icon_color
self.icon_custom_emoji_id = icon_custom_emoji_id
self.message_thread_id: int = message_thread_id
self.name: str = name
self.icon_color: int = icon_color
self.icon_custom_emoji_id: Optional[str] = icon_custom_emoji_id
self._id_attrs = (self.message_thread_id, self.name, self.icon_color)
@ -103,9 +104,9 @@ class ForumTopicCreated(TelegramObject):
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.name = name
self.icon_color = icon_color
self.icon_custom_emoji_id = icon_custom_emoji_id
self.name: str = name
self.icon_color: int = icon_color
self.icon_custom_emoji_id: Optional[str] = icon_custom_emoji_id
self._id_attrs = (self.name, self.icon_color)
@ -174,8 +175,8 @@ class ForumTopicEdited(TelegramObject):
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.name = name
self.icon_custom_emoji_id = icon_custom_emoji_id
self.name: Optional[str] = name
self.icon_custom_emoji_id: Optional[str] = icon_custom_emoji_id
self._id_attrs = (self.name, self.icon_custom_emoji_id)

View file

@ -18,7 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram Game."""
import sys
from typing import TYPE_CHECKING, Dict, List, Optional, Sequence
from typing import TYPE_CHECKING, Dict, List, Optional, Sequence, Tuple
from telegram._files.animation import Animation
from telegram._files.photosize import PhotoSize
@ -110,13 +110,13 @@ class Game(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.title = title
self.description = description
self.photo = parse_sequence_arg(photo)
self.title: str = title
self.description: str = description
self.photo: Tuple[PhotoSize, ...] = parse_sequence_arg(photo)
# Optionals
self.text = text
self.text_entities = parse_sequence_arg(text_entities)
self.animation = animation
self.text: Optional[str] = text
self.text_entities: Tuple[MessageEntity, ...] = parse_sequence_arg(text_entities)
self.animation: Optional[Animation] = animation
self._id_attrs = (self.title, self.description, self.photo)

View file

@ -50,9 +50,9 @@ class GameHighScore(TelegramObject):
def __init__(self, position: int, user: User, score: int, *, api_kwargs: JSONDict = None):
super().__init__(api_kwargs=api_kwargs)
self.position = position
self.user = user
self.score = score
self.position: int = position
self.user: User = user
self.score: int = score
self._id_attrs = (self.position, self.user, self.score)

View file

@ -196,17 +196,17 @@ class InlineKeyboardButton(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.text = text
self.text: str = text
# Optionals
self.url = url
self.login_url = login_url
self.callback_data = callback_data
self.switch_inline_query = switch_inline_query
self.switch_inline_query_current_chat = switch_inline_query_current_chat
self.callback_game = callback_game
self.pay = pay
self.web_app = web_app
self.url: Optional[str] = url
self.login_url: Optional[LoginUrl] = login_url
self.callback_data: Optional[Union[str, object]] = callback_data
self.switch_inline_query: Optional[str] = switch_inline_query
self.switch_inline_query_current_chat: Optional[str] = switch_inline_query_current_chat
self.callback_game: Optional[CallbackGame] = callback_game
self.pay: Optional[bool] = pay
self.web_app: Optional[WebAppInfo] = web_app
self._id_attrs = ()
self._set_id_attrs()

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram InlineKeyboardMarkup."""
from typing import TYPE_CHECKING, Optional, Sequence
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from telegram._inline.inlinekeyboardbutton import InlineKeyboardButton
from telegram._telegramobject import TelegramObject
@ -72,7 +72,9 @@ class InlineKeyboardMarkup(TelegramObject):
"InlineKeyboardButtons"
)
# Required
self.inline_keyboard = tuple(tuple(row) for row in inline_keyboard)
self.inline_keyboard: Tuple[Tuple[InlineKeyboardButton, ...], ...] = tuple(
tuple(row) for row in inline_keyboard
)
self._id_attrs = (self.inline_keyboard,)

View file

@ -100,14 +100,14 @@ class InlineQuery(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.id = id # pylint: disable=invalid-name
self.from_user = from_user
self.query = query
self.offset = offset
self.id: str = id # pylint: disable=invalid-name
self.from_user: User = from_user
self.query: str = query
self.offset: str = offset
# Optional
self.location = location
self.chat_type = chat_type
self.location: Optional[Location] = location
self.chat_type: Optional[str] = chat_type
self._id_attrs = (self.id,)

View file

@ -59,8 +59,8 @@ class InlineQueryResult(TelegramObject):
super().__init__(api_kwargs=api_kwargs)
# Required
self.type = type
self.id = str(id) # pylint: disable=invalid-name
self.type: str = type
self.id: str = str(id) # pylint: disable=invalid-name
self._id_attrs = (self.id,)

View file

@ -18,7 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultArticle."""
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
@ -103,14 +103,14 @@ class InlineQueryResultArticle(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.ARTICLE, id, api_kwargs=api_kwargs)
with self._unfrozen():
self.title = title
self.input_message_content = input_message_content
self.title: str = title
self.input_message_content: InputMessageContent = input_message_content
# Optional
self.reply_markup = reply_markup
self.url = url
self.hide_url = hide_url
self.description = description
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
self.url: Optional[str] = url
self.hide_url: Optional[bool] = hide_url
self.description: Optional[str] = description
self.thumb_url: Optional[str] = thumb_url
self.thumb_width: Optional[int] = thumb_width
self.thumb_height: Optional[int] = thumb_height

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultAudio."""
from typing import TYPE_CHECKING, Sequence
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
@ -117,14 +117,14 @@ class InlineQueryResultAudio(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.AUDIO, id, api_kwargs=api_kwargs)
with self._unfrozen():
self.audio_url = audio_url
self.title = title
self.audio_url: str = audio_url
self.title: str = title
# Optionals
self.performer = performer
self.audio_duration = audio_duration
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.performer: Optional[str] = performer
self.audio_duration: Optional[int] = audio_duration
self.caption: Optional[str] = caption
self.parse_mode: ODVInput[str] = parse_mode
self.caption_entities: Tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
self.input_message_content: Optional[InputMessageContent] = input_message_content

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultCachedAudio."""
from typing import TYPE_CHECKING, Sequence
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
@ -105,11 +105,11 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.AUDIO, id, api_kwargs=api_kwargs)
with self._unfrozen():
self.audio_file_id = audio_file_id
self.audio_file_id: str = audio_file_id
# Optionals
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.caption: Optional[str] = caption
self.parse_mode: ODVInput[str] = parse_mode
self.caption_entities: Tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
self.input_message_content: Optional[InputMessageContent] = input_message_content

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultCachedDocument."""
from typing import TYPE_CHECKING, Sequence
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
@ -113,13 +113,13 @@ class InlineQueryResultCachedDocument(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.DOCUMENT, id, api_kwargs=api_kwargs)
with self._unfrozen():
self.title = title
self.document_file_id = document_file_id
self.title: str = title
self.document_file_id: str = document_file_id
# Optionals
self.description = description
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.description: Optional[str] = description
self.caption: Optional[str] = caption
self.parse_mode: ODVInput[str] = parse_mode
self.caption_entities: Tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
self.input_message_content: Optional[InputMessageContent] = input_message_content

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultCachedGif."""
from typing import TYPE_CHECKING, Sequence
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
@ -110,12 +110,12 @@ class InlineQueryResultCachedGif(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.GIF, id, api_kwargs=api_kwargs)
with self._unfrozen():
self.gif_file_id = gif_file_id
self.gif_file_id: str = gif_file_id
# Optionals
self.title = title
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.title: Optional[str] = title
self.caption: Optional[str] = caption
self.parse_mode: ODVInput[str] = parse_mode
self.caption_entities: Tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
self.input_message_content: Optional[InputMessageContent] = input_message_content

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultMpeg4Gif."""
from typing import TYPE_CHECKING, Sequence
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
@ -110,12 +110,12 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.MPEG4GIF, id, api_kwargs=api_kwargs)
with self._unfrozen():
self.mpeg4_file_id = mpeg4_file_id
self.mpeg4_file_id: str = mpeg4_file_id
# Optionals
self.title = title
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.title: Optional[str] = title
self.caption: Optional[str] = caption
self.parse_mode: ODVInput[str] = parse_mode
self.caption_entities: Tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
self.input_message_content: Optional[InputMessageContent] = input_message_content

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultPhoto"""
from typing import TYPE_CHECKING, Sequence
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
@ -114,13 +114,13 @@ class InlineQueryResultCachedPhoto(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.PHOTO, id, api_kwargs=api_kwargs)
with self._unfrozen():
self.photo_file_id = photo_file_id
self.photo_file_id: str = photo_file_id
# Optionals
self.title = title
self.description = description
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.title: Optional[str] = title
self.description: Optional[str] = description
self.caption: Optional[str] = caption
self.parse_mode: ODVInput[str] = parse_mode
self.caption_entities: Tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
self.input_message_content: Optional[InputMessageContent] = input_message_content

View file

@ -18,7 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultCachedSticker."""
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
@ -74,8 +74,8 @@ class InlineQueryResultCachedSticker(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.STICKER, id, api_kwargs=api_kwargs)
with self._unfrozen():
self.sticker_file_id = sticker_file_id
self.sticker_file_id: str = sticker_file_id
# Optionals
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
self.input_message_content: Optional[InputMessageContent] = input_message_content

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultCachedVideo."""
from typing import TYPE_CHECKING, Sequence
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
@ -110,13 +110,13 @@ class InlineQueryResultCachedVideo(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.VIDEO, id, api_kwargs=api_kwargs)
with self._unfrozen():
self.video_file_id = video_file_id
self.title = title
self.video_file_id: str = video_file_id
self.title: str = title
# Optionals
self.description = description
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.description: Optional[str] = description
self.caption: Optional[str] = caption
self.parse_mode: ODVInput[str] = parse_mode
self.caption_entities: Tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
self.input_message_content: Optional[InputMessageContent] = input_message_content

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultCachedVoice."""
from typing import TYPE_CHECKING, Sequence
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
@ -109,12 +109,12 @@ class InlineQueryResultCachedVoice(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.VOICE, id, api_kwargs=api_kwargs)
with self._unfrozen():
self.voice_file_id = voice_file_id
self.title = title
self.voice_file_id: str = voice_file_id
self.title: str = title
# Optionals
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.caption: Optional[str] = caption
self.parse_mode: ODVInput[str] = parse_mode
self.caption_entities: Tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
self.input_message_content: Optional[InputMessageContent] = input_message_content

View file

@ -18,7 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultContact."""
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
@ -102,14 +102,14 @@ class InlineQueryResultContact(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.CONTACT, id, api_kwargs=api_kwargs)
with self._unfrozen():
self.phone_number = phone_number
self.first_name = first_name
self.phone_number: str = phone_number
self.first_name: str = first_name
# Optionals
self.last_name = last_name
self.vcard = vcard
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
self.last_name: Optional[str] = last_name
self.vcard: Optional[str] = vcard
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
self.input_message_content: Optional[InputMessageContent] = input_message_content
self.thumb_url: Optional[str] = thumb_url
self.thumb_width: Optional[int] = thumb_width
self.thumb_height: Optional[int] = thumb_height

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultDocument"""
from typing import TYPE_CHECKING, Sequence
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
@ -132,17 +132,17 @@ class InlineQueryResultDocument(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.DOCUMENT, id, api_kwargs=api_kwargs)
with self._unfrozen():
self.document_url = document_url
self.title = title
self.mime_type = mime_type
self.document_url: str = document_url
self.title: str = title
self.mime_type: str = mime_type
# Optionals
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.description = description
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
self.caption: Optional[str] = caption
self.parse_mode: ODVInput[str] = parse_mode
self.caption_entities: Tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
self.description: Optional[str] = description
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
self.input_message_content: Optional[InputMessageContent] = input_message_content
self.thumb_url: Optional[str] = thumb_url
self.thumb_width: Optional[int] = thumb_width
self.thumb_height: Optional[int] = thumb_height

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultGame."""
from typing import Optional
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
@ -59,7 +60,7 @@ class InlineQueryResultGame(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.GAME, id, api_kwargs=api_kwargs)
with self._unfrozen():
self.id = id
self.game_short_name = game_short_name
self.id: str = id
self.game_short_name: str = game_short_name
self.reply_markup = reply_markup
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultGif."""
from typing import TYPE_CHECKING, Sequence
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
@ -134,17 +134,17 @@ class InlineQueryResultGif(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.GIF, id, api_kwargs=api_kwargs)
with self._unfrozen():
self.gif_url = gif_url
self.thumb_url = thumb_url
self.gif_url: str = gif_url
self.thumb_url: str = thumb_url
# Optionals
self.gif_width = gif_width
self.gif_height = gif_height
self.gif_duration = gif_duration
self.title = title
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_mime_type = thumb_mime_type
self.gif_width: Optional[int] = gif_width
self.gif_height: Optional[int] = gif_height
self.gif_duration: Optional[int] = gif_duration
self.title: Optional[str] = title
self.caption: Optional[str] = caption
self.parse_mode: ODVInput[str] = parse_mode
self.caption_entities: Tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
self.input_message_content: Optional[InputMessageContent] = input_message_content
self.thumb_mime_type: Optional[str] = thumb_mime_type

View file

@ -18,7 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultLocation."""
from typing import TYPE_CHECKING, ClassVar
from typing import TYPE_CHECKING, ClassVar, Optional
from telegram import constants
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
@ -136,20 +136,20 @@ class InlineQueryResultLocation(InlineQueryResult):
# Required
super().__init__(constants.InlineQueryResultType.LOCATION, id, api_kwargs=api_kwargs)
with self._unfrozen():
self.latitude = latitude
self.longitude = longitude
self.title = title
self.latitude: float = latitude
self.longitude: float = longitude
self.title: str = title
# Optionals
self.live_period = live_period
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
self.horizontal_accuracy = horizontal_accuracy
self.heading = heading
self.proximity_alert_radius = (
self.live_period: Optional[int] = live_period
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
self.input_message_content: Optional[InputMessageContent] = input_message_content
self.thumb_url: Optional[str] = thumb_url
self.thumb_width: Optional[int] = thumb_width
self.thumb_height: Optional[int] = thumb_height
self.horizontal_accuracy: Optional[float] = horizontal_accuracy
self.heading: Optional[int] = heading
self.proximity_alert_radius: Optional[int] = (
int(proximity_alert_radius) if proximity_alert_radius else None
)

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultMpeg4Gif."""
from typing import TYPE_CHECKING, Sequence
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
@ -137,17 +137,17 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.MPEG4GIF, id, api_kwargs=api_kwargs)
with self._unfrozen():
self.mpeg4_url = mpeg4_url
self.thumb_url = thumb_url
self.mpeg4_url: str = mpeg4_url
self.thumb_url: str = thumb_url
# Optional
self.mpeg4_width = mpeg4_width
self.mpeg4_height = mpeg4_height
self.mpeg4_duration = mpeg4_duration
self.title = title
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_mime_type = thumb_mime_type
self.mpeg4_width: Optional[int] = mpeg4_width
self.mpeg4_height: Optional[int] = mpeg4_height
self.mpeg4_duration: Optional[int] = mpeg4_duration
self.title: Optional[str] = title
self.caption: Optional[str] = caption
self.parse_mode: ODVInput[str] = parse_mode
self.caption_entities: Tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
self.input_message_content: Optional[InputMessageContent] = input_message_content
self.thumb_mime_type: Optional[str] = thumb_mime_type

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultPhoto."""
from typing import TYPE_CHECKING, Sequence
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
@ -127,16 +127,16 @@ class InlineQueryResultPhoto(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.PHOTO, id, api_kwargs=api_kwargs)
with self._unfrozen():
self.photo_url = photo_url
self.thumb_url = thumb_url
self.photo_url: str = photo_url
self.thumb_url: str = thumb_url
# Optionals
self.photo_width = photo_width
self.photo_height = photo_height
self.title = title
self.description = description
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.photo_width: Optional[int] = photo_width
self.photo_height: Optional[int] = photo_height
self.title: Optional[str] = title
self.description: Optional[str] = description
self.caption: Optional[str] = caption
self.parse_mode: ODVInput[str] = parse_mode
self.caption_entities: Tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
self.input_message_content: Optional[InputMessageContent] = input_message_content

View file

@ -18,7 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultVenue."""
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
@ -129,18 +129,18 @@ class InlineQueryResultVenue(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.VENUE, id, api_kwargs=api_kwargs)
with self._unfrozen():
self.latitude = latitude
self.longitude = longitude
self.title = title
self.address = address
self.latitude: float = latitude
self.longitude: float = longitude
self.title: str = title
self.address: str = address
# Optional
self.foursquare_id = foursquare_id
self.foursquare_type = foursquare_type
self.google_place_id = google_place_id
self.google_place_type = google_place_type
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
self.foursquare_id: Optional[str] = foursquare_id
self.foursquare_type: Optional[str] = foursquare_type
self.google_place_id: Optional[str] = google_place_id
self.google_place_type: Optional[str] = google_place_type
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
self.input_message_content: Optional[InputMessageContent] = input_message_content
self.thumb_url: Optional[str] = thumb_url
self.thumb_width: Optional[int] = thumb_width
self.thumb_height: Optional[int] = thumb_height

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultVideo."""
from typing import TYPE_CHECKING, Sequence
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
@ -145,18 +145,18 @@ class InlineQueryResultVideo(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.VIDEO, id, api_kwargs=api_kwargs)
with self._unfrozen():
self.video_url = video_url
self.mime_type = mime_type
self.thumb_url = thumb_url
self.title = title
self.video_url: str = video_url
self.mime_type: str = mime_type
self.thumb_url: str = thumb_url
self.title: str = title
# Optional
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.video_width = video_width
self.video_height = video_height
self.video_duration = video_duration
self.description = description
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.caption: Optional[str] = caption
self.parse_mode: ODVInput[str] = parse_mode
self.caption_entities: Tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
self.video_width: Optional[int] = video_width
self.video_height: Optional[int] = video_height
self.video_duration: Optional[int] = video_duration
self.description: Optional[str] = description
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
self.input_message_content: Optional[InputMessageContent] = input_message_content

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultVoice."""
from typing import TYPE_CHECKING, Sequence
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
@ -115,13 +115,13 @@ class InlineQueryResultVoice(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.VOICE, id, api_kwargs=api_kwargs)
with self._unfrozen():
self.voice_url = voice_url
self.title = title
self.voice_url: str = voice_url
self.title: str = title
# Optional
self.voice_duration = voice_duration
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.voice_duration: Optional[int] = voice_duration
self.caption: Optional[str] = caption
self.parse_mode: ODVInput[str] = parse_mode
self.caption_entities: Tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
self.input_message_content: Optional[InputMessageContent] = input_message_content

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InputContactMessageContent."""
from typing import Optional
from telegram._inline.inputmessagecontent import InputMessageContent
from telegram._utils.types import JSONDict
@ -58,10 +59,10 @@ class InputContactMessageContent(InputMessageContent):
super().__init__(api_kwargs=api_kwargs)
with self._unfrozen():
# Required
self.phone_number = phone_number
self.first_name = first_name
self.phone_number: str = phone_number
self.first_name: str = first_name
# Optionals
self.last_name = last_name
self.vcard = vcard
self.last_name: Optional[str] = last_name
self.vcard: Optional[str] = vcard
self._id_attrs = (self.phone_number,)

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a class that represents a Telegram InputInvoiceMessageContent."""
from typing import TYPE_CHECKING, Optional, Sequence
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from telegram._inline.inputmessagecontent import InputMessageContent
from telegram._payment.labeledprice import LabeledPrice
@ -213,27 +213,27 @@ class InputInvoiceMessageContent(InputMessageContent):
super().__init__(api_kwargs=api_kwargs)
with self._unfrozen():
# Required
self.title = title
self.description = description
self.payload = payload
self.provider_token = provider_token
self.currency = currency
self.prices = parse_sequence_arg(prices)
self.title: str = title
self.description: str = description
self.payload: str = payload
self.provider_token: str = provider_token
self.currency: str = currency
self.prices: Tuple[LabeledPrice, ...] = parse_sequence_arg(prices)
# Optionals
self.max_tip_amount = max_tip_amount
self.suggested_tip_amounts = parse_sequence_arg(suggested_tip_amounts)
self.provider_data = provider_data
self.photo_url = photo_url
self.photo_size = photo_size
self.photo_width = photo_width
self.photo_height = photo_height
self.need_name = need_name
self.need_phone_number = need_phone_number
self.need_email = need_email
self.need_shipping_address = need_shipping_address
self.send_phone_number_to_provider = send_phone_number_to_provider
self.send_email_to_provider = send_email_to_provider
self.is_flexible = is_flexible
self.max_tip_amount: Optional[int] = max_tip_amount
self.suggested_tip_amounts: Tuple[int, ...] = parse_sequence_arg(suggested_tip_amounts)
self.provider_data: Optional[str] = provider_data
self.photo_url: Optional[str] = photo_url
self.photo_size: Optional[int] = photo_size
self.photo_width: Optional[int] = photo_width
self.photo_height: Optional[int] = photo_height
self.need_name: Optional[bool] = need_name
self.need_phone_number: Optional[bool] = need_phone_number
self.need_email: Optional[bool] = need_email
self.need_shipping_address: Optional[bool] = need_shipping_address
self.send_phone_number_to_provider: Optional[bool] = send_phone_number_to_provider
self.send_email_to_provider: Optional[bool] = send_email_to_provider
self.is_flexible: Optional[bool] = is_flexible
self._id_attrs = (
self.title,

View file

@ -18,7 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InputLocationMessageContent."""
from typing import ClassVar
from typing import ClassVar, Optional
from telegram import constants
from telegram._inline.inputmessagecontent import InputMessageContent
@ -93,14 +93,14 @@ class InputLocationMessageContent(InputMessageContent):
super().__init__(api_kwargs=api_kwargs)
with self._unfrozen():
# Required
self.latitude = latitude
self.longitude = longitude
self.latitude: float = latitude
self.longitude: float = longitude
# Optionals
self.live_period = live_period
self.horizontal_accuracy = horizontal_accuracy
self.heading = heading
self.proximity_alert_radius = (
self.live_period: Optional[int] = live_period
self.horizontal_accuracy: Optional[float] = horizontal_accuracy
self.heading: Optional[int] = heading
self.proximity_alert_radius: Optional[int] = (
int(proximity_alert_radius) if proximity_alert_radius else None
)

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InputTextMessageContent."""
from typing import Sequence
from typing import Sequence, Tuple
from telegram._inline.inputmessagecontent import InputMessageContent
from telegram._messageentity import MessageEntity
@ -81,10 +81,10 @@ class InputTextMessageContent(InputMessageContent):
super().__init__(api_kwargs=api_kwargs)
with self._unfrozen():
# Required
self.message_text = message_text
self.message_text: str = message_text
# Optionals
self.parse_mode = parse_mode
self.entities = parse_sequence_arg(entities)
self.disable_web_page_preview = disable_web_page_preview
self.parse_mode: ODVInput[str] = parse_mode
self.entities: Tuple[MessageEntity, ...] = parse_sequence_arg(entities)
self.disable_web_page_preview: ODVInput[bool] = disable_web_page_preview
self._id_attrs = (self.message_text,)

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InputVenueMessageContent."""
from typing import Optional
from telegram._inline.inputmessagecontent import InputMessageContent
from telegram._utils.types import JSONDict
@ -90,15 +91,15 @@ class InputVenueMessageContent(InputMessageContent):
super().__init__(api_kwargs=api_kwargs)
with self._unfrozen():
# Required
self.latitude = latitude
self.longitude = longitude
self.title = title
self.address = address
self.latitude: float = latitude
self.longitude: float = longitude
self.title: str = title
self.address: str = address
# Optionals
self.foursquare_id = foursquare_id
self.foursquare_type = foursquare_type
self.google_place_id = google_place_id
self.google_place_type = google_place_type
self.foursquare_id: Optional[str] = foursquare_id
self.foursquare_type: Optional[str] = foursquare_type
self.google_place_id: Optional[str] = google_place_id
self.google_place_type: Optional[str] = google_place_type
self._id_attrs = (
self.latitude,

View file

@ -99,12 +99,12 @@ class KeyboardButton(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.text = text
self.text: str = text
# Optionals
self.request_contact = request_contact
self.request_location = request_location
self.request_poll = request_poll
self.web_app = web_app
self.request_contact: Optional[bool] = request_contact
self.request_location: Optional[bool] = request_location
self.request_poll: Optional[KeyboardButtonPollType] = request_poll
self.web_app: Optional[WebAppInfo] = web_app
self._id_attrs = (
self.text,

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a type of a Telegram Poll."""
from typing import Optional
from telegram._telegramobject import TelegramObject
from telegram._utils.types import JSONDict
@ -50,7 +51,7 @@ class KeyboardButtonPollType(TelegramObject):
self, type: str = None, *, api_kwargs: JSONDict = None # skipcq: PYL-W0622
): # pylint: disable=redefined-builtin
super().__init__(api_kwargs=api_kwargs)
self.type = type
self.type: Optional[str] = type
self._id_attrs = (self.type,)

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram LoginUrl."""
from typing import Optional
from telegram._telegramobject import TelegramObject
from telegram._utils.types import JSONDict
@ -93,11 +94,11 @@ class LoginUrl(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.url = url
self.url: str = url
# Optional
self.forward_text = forward_text
self.bot_username = bot_username
self.request_write_access = request_write_access
self.forward_text: Optional[bool] = forward_text
self.bot_username: Optional[str] = bot_username
self.request_write_access: Optional[bool] = request_write_access
self._id_attrs = (self.url,)

View file

@ -58,7 +58,7 @@ class MenuButton(TelegramObject):
self, type: str, *, api_kwargs: JSONDict = None # skipcq: PYL-W0622
): # pylint: disable=redefined-builtin
super().__init__(api_kwargs=api_kwargs)
self.type = type
self.type: str = type
self._id_attrs = (self.type,)
@ -150,8 +150,8 @@ class MenuButtonWebApp(MenuButton):
def __init__(self, text: str, web_app: WebAppInfo, *, api_kwargs: JSONDict = None):
super().__init__(type=constants.MenuButtonType.WEB_APP, api_kwargs=api_kwargs)
with self._unfrozen():
self.text = text
self.web_app = web_app
self.text: str = text
self.web_app: WebAppInfo = web_app
self._id_attrs = (self.type, self.text, self.web_app)

View file

@ -699,76 +699,86 @@ class Message(TelegramObject):
super().__init__(api_kwargs=api_kwargs)
# Required
self.message_id = message_id
self.message_id: int = message_id
# Optionals
self.from_user = from_user
self.sender_chat = sender_chat
self.date = date
self.chat = chat
self.forward_from = forward_from
self.forward_from_chat = forward_from_chat
self.forward_date = forward_date
self.is_automatic_forward = is_automatic_forward
self.reply_to_message = reply_to_message
self.edit_date = edit_date
self.has_protected_content = has_protected_content
self.text = text
self.entities = parse_sequence_arg(entities)
self.caption_entities = parse_sequence_arg(caption_entities)
self.audio = audio
self.game = game
self.document = document
self.photo = parse_sequence_arg(photo)
self.sticker = sticker
self.video = video
self.voice = voice
self.video_note = video_note
self.caption = caption
self.contact = contact
self.location = location
self.venue = venue
self.new_chat_members = parse_sequence_arg(new_chat_members)
self.left_chat_member = left_chat_member
self.new_chat_title = new_chat_title
self.new_chat_photo = parse_sequence_arg(new_chat_photo)
self.delete_chat_photo = bool(delete_chat_photo)
self.group_chat_created = bool(group_chat_created)
self.supergroup_chat_created = bool(supergroup_chat_created)
self.migrate_to_chat_id = migrate_to_chat_id
self.migrate_from_chat_id = migrate_from_chat_id
self.channel_chat_created = bool(channel_chat_created)
self.message_auto_delete_timer_changed = message_auto_delete_timer_changed
self.pinned_message = pinned_message
self.forward_from_message_id = forward_from_message_id
self.invoice = invoice
self.successful_payment = successful_payment
self.connected_website = connected_website
self.forward_signature = forward_signature
self.forward_sender_name = forward_sender_name
self.author_signature = author_signature
self.media_group_id = media_group_id
self.animation = animation
self.passport_data = passport_data
self.poll = poll
self.dice = dice
self.via_bot = via_bot
self.proximity_alert_triggered = proximity_alert_triggered
self.video_chat_scheduled = video_chat_scheduled
self.video_chat_started = video_chat_started
self.video_chat_ended = video_chat_ended
self.video_chat_participants_invited = video_chat_participants_invited
self.reply_markup = reply_markup
self.web_app_data = web_app_data
self.is_topic_message = is_topic_message
self.message_thread_id = message_thread_id
self.forum_topic_created = forum_topic_created
self.forum_topic_closed = forum_topic_closed
self.forum_topic_reopened = forum_topic_reopened
self.forum_topic_edited = forum_topic_edited
self.general_forum_topic_hidden = general_forum_topic_hidden
self.general_forum_topic_unhidden = general_forum_topic_unhidden
self.write_access_allowed = write_access_allowed
self.has_media_spoiler = has_media_spoiler
self.from_user: Optional[User] = from_user
self.sender_chat: Optional[Chat] = sender_chat
self.date: datetime.datetime = date
self.chat: Chat = chat
self.forward_from: Optional[User] = forward_from
self.forward_from_chat: Optional[Chat] = forward_from_chat
self.forward_date: Optional[datetime.datetime] = forward_date
self.is_automatic_forward: Optional[bool] = is_automatic_forward
self.reply_to_message: Optional[Message] = reply_to_message
self.edit_date: Optional[datetime.datetime] = edit_date
self.has_protected_content: Optional[bool] = has_protected_content
self.text: Optional[str] = text
self.entities: Tuple["MessageEntity", ...] = parse_sequence_arg(entities)
self.caption_entities: Tuple["MessageEntity", ...] = parse_sequence_arg(caption_entities)
self.audio: Optional[Audio] = audio
self.game: Optional[Game] = game
self.document: Optional[Document] = document
self.photo: Tuple[PhotoSize, ...] = parse_sequence_arg(photo)
self.sticker: Optional[Sticker] = sticker
self.video: Optional[Video] = video
self.voice: Optional[Voice] = voice
self.video_note: Optional[VideoNote] = video_note
self.caption: Optional[str] = caption
self.contact: Optional[Contact] = contact
self.location: Optional[Location] = location
self.venue: Optional[Venue] = venue
self.new_chat_members: Tuple[User, ...] = parse_sequence_arg(new_chat_members)
self.left_chat_member: Optional[User] = left_chat_member
self.new_chat_title: Optional[str] = new_chat_title
self.new_chat_photo: Tuple[PhotoSize, ...] = parse_sequence_arg(new_chat_photo)
self.delete_chat_photo: Optional[bool] = bool(delete_chat_photo)
self.group_chat_created: Optional[bool] = bool(group_chat_created)
self.supergroup_chat_created: Optional[bool] = bool(supergroup_chat_created)
self.migrate_to_chat_id: Optional[int] = migrate_to_chat_id
self.migrate_from_chat_id: Optional[int] = migrate_from_chat_id
self.channel_chat_created: Optional[bool] = bool(channel_chat_created)
self.message_auto_delete_timer_changed: Optional[
MessageAutoDeleteTimerChanged
] = message_auto_delete_timer_changed
self.pinned_message: Optional[Message] = pinned_message
self.forward_from_message_id: Optional[int] = forward_from_message_id
self.invoice: Optional[Invoice] = invoice
self.successful_payment: Optional[SuccessfulPayment] = successful_payment
self.connected_website: Optional[str] = connected_website
self.forward_signature: Optional[str] = forward_signature
self.forward_sender_name: Optional[str] = forward_sender_name
self.author_signature: Optional[str] = author_signature
self.media_group_id: Optional[str] = media_group_id
self.animation: Optional[Animation] = animation
self.passport_data: Optional[PassportData] = passport_data
self.poll: Optional[Poll] = poll
self.dice: Optional[Dice] = dice
self.via_bot: Optional[User] = via_bot
self.proximity_alert_triggered: Optional[
ProximityAlertTriggered
] = proximity_alert_triggered
self.video_chat_scheduled: Optional[VideoChatScheduled] = video_chat_scheduled
self.video_chat_started: Optional[VideoChatStarted] = video_chat_started
self.video_chat_ended: Optional[VideoChatEnded] = video_chat_ended
self.video_chat_participants_invited: Optional[
VideoChatParticipantsInvited
] = video_chat_participants_invited
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
self.web_app_data: Optional[WebAppData] = web_app_data
self.is_topic_message: Optional[bool] = is_topic_message
self.message_thread_id: Optional[int] = message_thread_id
self.forum_topic_created: Optional[ForumTopicCreated] = forum_topic_created
self.forum_topic_closed: Optional[ForumTopicClosed] = forum_topic_closed
self.forum_topic_reopened: Optional[ForumTopicReopened] = forum_topic_reopened
self.forum_topic_edited: Optional[ForumTopicEdited] = forum_topic_edited
self.general_forum_topic_hidden: Optional[
GeneralForumTopicHidden
] = general_forum_topic_hidden
self.general_forum_topic_unhidden: Optional[
GeneralForumTopicUnhidden
] = general_forum_topic_unhidden
self.write_access_allowed: Optional[WriteAccessAllowed] = write_access_allowed
self.has_media_spoiler: Optional[bool] = has_media_spoiler
self._effective_attachment = DEFAULT_NONE

View file

@ -51,7 +51,7 @@ class MessageAutoDeleteTimerChanged(TelegramObject):
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.message_auto_delete_time = message_auto_delete_time
self.message_auto_delete_time: int = message_auto_delete_time
self._id_attrs = (self.message_auto_delete_time,)

View file

@ -105,14 +105,14 @@ class MessageEntity(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.type = enum.get_member(constants.MessageEntityType, type, type)
self.offset = offset
self.length = length
self.type: str = enum.get_member(constants.MessageEntityType, type, type)
self.offset: int = offset
self.length: int = length
# Optionals
self.url = url
self.user = user
self.language = language
self.custom_emoji_id = custom_emoji_id
self.url: Optional[str] = url
self.user: Optional[User] = user
self.language: Optional[str] = language
self.custom_emoji_id: Optional[str] = custom_emoji_id
self._id_attrs = (self.type, self.offset, self.length)

View file

@ -39,7 +39,7 @@ class MessageId(TelegramObject):
def __init__(self, message_id: int, *, api_kwargs: JSONDict = None):
super().__init__(api_kwargs=api_kwargs)
self.message_id = message_id
self.message_id: int = message_id
self._id_attrs = (self.message_id,)

View file

@ -19,7 +19,7 @@
# pylint: disable=missing-module-docstring, redefined-builtin
import json
from base64 import b64decode
from typing import TYPE_CHECKING, Optional, Sequence, no_type_check
from typing import TYPE_CHECKING, Optional, Sequence, Tuple, no_type_check
try:
from cryptography.hazmat.backends import default_backend
@ -147,9 +147,9 @@ class EncryptedCredentials(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.data = data
self.hash = hash
self.secret = secret
self.data: str = data
self.hash: str = hash
self.secret: str = secret
self._id_attrs = (self.data, self.hash, self.secret)
@ -226,8 +226,8 @@ class Credentials(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.secure_data = secure_data
self.nonce = nonce
self.secure_data: SecureData = secure_data
self.nonce: str = nonce
self._freeze()
@ -327,17 +327,17 @@ class SecureData(TelegramObject):
super().__init__(api_kwargs=api_kwargs)
# Optionals
self.temporary_registration = temporary_registration
self.passport_registration = passport_registration
self.rental_agreement = rental_agreement
self.bank_statement = bank_statement
self.utility_bill = utility_bill
self.address = address
self.identity_card = identity_card
self.driver_license = driver_license
self.internal_passport = internal_passport
self.passport = passport
self.personal_details = personal_details
self.temporary_registration: Optional[SecureValue] = temporary_registration
self.passport_registration: Optional[SecureValue] = passport_registration
self.rental_agreement: Optional[SecureValue] = rental_agreement
self.bank_statement: Optional[SecureValue] = bank_statement
self.utility_bill: Optional[SecureValue] = utility_bill
self.address: Optional[SecureValue] = address
self.identity_card: Optional[SecureValue] = identity_card
self.driver_license: Optional[SecureValue] = driver_license
self.internal_passport: Optional[SecureValue] = internal_passport
self.passport: Optional[SecureValue] = passport
self.personal_details: Optional[SecureValue] = personal_details
self._freeze()
@ -438,12 +438,12 @@ class SecureValue(TelegramObject):
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.data = data
self.front_side = front_side
self.reverse_side = reverse_side
self.selfie = selfie
self.files = parse_sequence_arg(files)
self.translation = parse_sequence_arg(translation)
self.data: Optional[DataCredentials] = data
self.front_side: Optional[FileCredentials] = front_side
self.reverse_side: Optional[FileCredentials] = reverse_side
self.selfie: Optional[FileCredentials] = selfie
self.files: Tuple["FileCredentials", ...] = parse_sequence_arg(files)
self.translation: Tuple["FileCredentials", ...] = parse_sequence_arg(translation)
self._freeze()
@ -475,12 +475,12 @@ class _CredentialsBase(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
with self._unfrozen():
self.hash = hash
self.secret = secret
self.hash: str = hash
self.secret: str = secret
# Aliases just to be sure
self.file_hash = self.hash
self.data_hash = self.hash
self.file_hash: str = self.hash
self.data_hash: str = self.hash
class DataCredentials(_CredentialsBase):

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
# pylint: disable=missing-module-docstring
from typing import Optional
from telegram._telegramobject import TelegramObject
from telegram._utils.types import JSONDict
@ -89,16 +90,16 @@ class PersonalDetails(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.first_name = first_name
self.last_name = last_name
self.middle_name = middle_name
self.birth_date = birth_date
self.gender = gender
self.country_code = country_code
self.residence_country_code = residence_country_code
self.first_name_native = first_name_native
self.last_name_native = last_name_native
self.middle_name_native = middle_name_native
self.first_name: str = first_name
self.last_name: str = last_name
self.middle_name: Optional[str] = middle_name
self.birth_date: str = birth_date
self.gender: str = gender
self.country_code: str = country_code
self.residence_country_code: str = residence_country_code
self.first_name_native: Optional[str] = first_name_native
self.last_name_native: Optional[str] = last_name_native
self.middle_name_native: Optional[str] = middle_name_native
self._freeze()
@ -146,12 +147,12 @@ class ResidentialAddress(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.street_line1 = street_line1
self.street_line2 = street_line2
self.city = city
self.state = state
self.country_code = country_code
self.post_code = post_code
self.street_line1: str = street_line1
self.street_line2: str = street_line2
self.city: str = city
self.state: str = state
self.country_code: str = country_code
self.post_code: str = post_code
self._freeze()
@ -179,7 +180,7 @@ class IdDocumentData(TelegramObject):
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.document_no = document_no
self.expiry_date = expiry_date
self.document_no: str = document_no
self.expiry_date: str = expiry_date
self._freeze()

View file

@ -18,7 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram EncryptedPassportElement."""
from base64 import b64decode
from typing import TYPE_CHECKING, Optional, Sequence
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from telegram._passport.credentials import decrypt_json
from telegram._passport.data import IdDocumentData, PersonalDetails, ResidentialAddress
@ -166,17 +166,17 @@ class EncryptedPassportElement(TelegramObject):
super().__init__(api_kwargs=api_kwargs)
# Required
self.type = type
self.type: str = type
# Optionals
self.data = data
self.phone_number = phone_number
self.email = email
self.files = parse_sequence_arg(files)
self.front_side = front_side
self.reverse_side = reverse_side
self.selfie = selfie
self.translation = parse_sequence_arg(translation)
self.hash = hash
self.data: Optional[PersonalDetails] = data
self.phone_number: Optional[str] = phone_number
self.email: Optional[str] = email
self.files: Tuple[PassportFile, ...] = parse_sequence_arg(files)
self.front_side: Optional[PassportFile] = front_side
self.reverse_side: Optional[PassportFile] = reverse_side
self.selfie: Optional[PassportFile] = selfie
self.translation: Tuple[PassportFile, ...] = parse_sequence_arg(translation)
self.hash: str = hash
self._id_attrs = (
self.type,

View file

@ -72,8 +72,8 @@ class PassportData(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
self.data = parse_sequence_arg(data)
self.credentials = credentials
self.data: Tuple[EncryptedPassportElement, ...] = parse_sequence_arg(data)
self.credentials: EncryptedCredentials = credentials
self._decrypted_data: Optional[Tuple[EncryptedPassportElement]] = None
self._id_attrs = tuple([x.type for x in data] + [credentials.hash])

View file

@ -49,9 +49,9 @@ class PassportElementError(TelegramObject):
def __init__(self, source: str, type: str, message: str, *, api_kwargs: JSONDict = None):
super().__init__(api_kwargs=api_kwargs)
# Required
self.source = str(source)
self.type = str(type)
self.message = str(message)
self.source: str = str(source)
self.type: str = str(type)
self.message: str = str(message)
self._id_attrs = (self.source, self.type)
@ -99,8 +99,8 @@ class PassportElementErrorDataField(PassportElementError):
# Required
super().__init__("data", type, message, api_kwargs=api_kwargs)
with self._unfrozen():
self.field_name = field_name
self.data_hash = data_hash
self.field_name: str = field_name
self.data_hash: str = data_hash
self._id_attrs = (
self.source,
@ -142,7 +142,7 @@ class PassportElementErrorFile(PassportElementError):
# Required
super().__init__("file", type, message, api_kwargs=api_kwargs)
with self._unfrozen():
self.file_hash = file_hash
self.file_hash: str = file_hash
self._id_attrs = (self.source, self.type, self.file_hash, self.message)
@ -178,7 +178,7 @@ class PassportElementErrorFiles(PassportElementError):
# Required
super().__init__("files", type, message, api_kwargs=api_kwargs)
with self._unfrozen():
self.file_hashes = file_hashes
self.file_hashes: str = file_hashes
self._id_attrs = (self.source, self.type, self.message) + tuple(file_hashes)
@ -214,7 +214,7 @@ class PassportElementErrorFrontSide(PassportElementError):
# Required
super().__init__("front_side", type, message, api_kwargs=api_kwargs)
with self._unfrozen():
self.file_hash = file_hash
self.file_hash: str = file_hash
self._id_attrs = (self.source, self.type, self.file_hash, self.message)
@ -250,7 +250,7 @@ class PassportElementErrorReverseSide(PassportElementError):
# Required
super().__init__("reverse_side", type, message, api_kwargs=api_kwargs)
with self._unfrozen():
self.file_hash = file_hash
self.file_hash: str = file_hash
self._id_attrs = (self.source, self.type, self.file_hash, self.message)
@ -284,7 +284,7 @@ class PassportElementErrorSelfie(PassportElementError):
# Required
super().__init__("selfie", type, message, api_kwargs=api_kwargs)
with self._unfrozen():
self.file_hash = file_hash
self.file_hash: str = file_hash
self._id_attrs = (self.source, self.type, self.file_hash, self.message)
@ -322,7 +322,7 @@ class PassportElementErrorTranslationFile(PassportElementError):
# Required
super().__init__("translation_file", type, message, api_kwargs=api_kwargs)
with self._unfrozen():
self.file_hash = file_hash
self.file_hash: str = file_hash
self._id_attrs = (self.source, self.type, self.file_hash, self.message)
@ -360,7 +360,7 @@ class PassportElementErrorTranslationFiles(PassportElementError):
# Required
super().__init__("translation_files", type, message, api_kwargs=api_kwargs)
with self._unfrozen():
self.file_hashes = file_hashes
self.file_hashes: str = file_hashes
self._id_attrs = (self.source, self.type, self.message) + tuple(file_hashes)
@ -392,6 +392,6 @@ class PassportElementErrorUnspecified(PassportElementError):
# Required
super().__init__("unspecified", type, message, api_kwargs=api_kwargs)
with self._unfrozen():
self.element_hash = element_hash
self.element_hash: str = element_hash
self._id_attrs = (self.source, self.type, self.element_hash, self.message)

View file

@ -78,13 +78,13 @@ class PassportFile(TelegramObject):
super().__init__(api_kwargs=api_kwargs)
# Required
self.file_id = file_id
self.file_unique_id = file_unique_id
self.file_size = file_size
self.file_date = file_date
self.file_id: str = file_id
self.file_unique_id: str = file_unique_id
self.file_size: int = file_size
self.file_date: int = file_date
# Optionals
self._credentials = credentials
self._credentials: Optional[FileCredentials] = credentials
self._id_attrs = (self.file_unique_id,)

View file

@ -79,11 +79,11 @@ class Invoice(TelegramObject):
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.title = title
self.description = description
self.start_parameter = start_parameter
self.currency = currency
self.total_amount = total_amount
self.title: str = title
self.description: str = description
self.start_parameter: str = start_parameter
self.currency: str = currency
self.total_amount: int = total_amount
self._id_attrs = (
self.title,

View file

@ -55,8 +55,8 @@ class LabeledPrice(TelegramObject):
def __init__(self, label: str, amount: int, *, api_kwargs: JSONDict = None):
super().__init__(api_kwargs=api_kwargs)
self.label = label
self.amount = amount
self.label: str = label
self.amount: int = amount
self._id_attrs = (self.label, self.amount)

View file

@ -61,10 +61,10 @@ class OrderInfo(TelegramObject):
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.name = name
self.phone_number = phone_number
self.email = email
self.shipping_address = shipping_address
self.name: Optional[str] = name
self.phone_number: Optional[str] = phone_number
self.email: Optional[str] = email
self.shipping_address: Optional[str] = shipping_address
self._id_attrs = (self.name, self.phone_number, self.email, self.shipping_address)

View file

@ -95,13 +95,13 @@ class PreCheckoutQuery(TelegramObject):
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.id = id # pylint: disable=invalid-name
self.from_user = from_user
self.currency = currency
self.total_amount = total_amount
self.invoice_payload = invoice_payload
self.shipping_option_id = shipping_option_id
self.order_info = order_info
self.id: str = id # pylint: disable=invalid-name
self.from_user: User = from_user
self.currency: str = currency
self.total_amount: int = total_amount
self.invoice_payload: str = invoice_payload
self.shipping_option_id: Optional[str] = shipping_option_id
self.order_info: Optional[OrderInfo] = order_info
self._id_attrs = (self.id,)

View file

@ -68,12 +68,12 @@ class ShippingAddress(TelegramObject):
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.country_code = country_code
self.state = state
self.city = city
self.street_line1 = street_line1
self.street_line2 = street_line2
self.post_code = post_code
self.country_code: str = country_code
self.state: str = state
self.city: str = city
self.street_line1: str = street_line1
self.street_line2: str = street_line2
self.post_code: str = post_code
self._id_attrs = (
self.country_code,

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram ShippingOption."""
from typing import TYPE_CHECKING, Sequence
from typing import TYPE_CHECKING, Sequence, Tuple
from telegram._telegramobject import TelegramObject
from telegram._utils.argumentparsing import parse_sequence_arg
@ -66,9 +66,9 @@ class ShippingOption(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
self.id = id # pylint: disable=invalid-name
self.title = title
self.prices = parse_sequence_arg(prices)
self.id: str = id # pylint: disable=invalid-name
self.title: str = title
self.prices: Tuple["LabeledPrice", ...] = parse_sequence_arg(prices)
self._id_attrs = (self.id,)

View file

@ -67,10 +67,10 @@ class ShippingQuery(TelegramObject):
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.id = id # pylint: disable=invalid-name
self.from_user = from_user
self.invoice_payload = invoice_payload
self.shipping_address = shipping_address
self.id: str = id # pylint: disable=invalid-name
self.from_user: User = from_user
self.invoice_payload: str = invoice_payload
self.shipping_address: ShippingAddress = shipping_address
self._id_attrs = (self.id,)

View file

@ -90,13 +90,13 @@ class SuccessfulPayment(TelegramObject):
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.currency = currency
self.total_amount = total_amount
self.invoice_payload = invoice_payload
self.shipping_option_id = shipping_option_id
self.order_info = order_info
self.telegram_payment_charge_id = telegram_payment_charge_id
self.provider_payment_charge_id = provider_payment_charge_id
self.currency: str = currency
self.total_amount: int = total_amount
self.invoice_payload: str = invoice_payload
self.shipping_option_id: Optional[str] = shipping_option_id
self.order_info: Optional[OrderInfo] = order_info
self.telegram_payment_charge_id: str = telegram_payment_charge_id
self.provider_payment_charge_id: str = provider_payment_charge_id
self._id_attrs = (self.telegram_payment_charge_id, self.provider_payment_charge_id)

View file

@ -19,7 +19,7 @@
"""This module contains an object that represents a Telegram Poll."""
import datetime
import sys
from typing import TYPE_CHECKING, ClassVar, Dict, List, Optional, Sequence
from typing import TYPE_CHECKING, ClassVar, Dict, List, Optional, Sequence, Tuple
from telegram import constants
from telegram._messageentity import MessageEntity
@ -59,8 +59,8 @@ class PollOption(TelegramObject):
def __init__(self, text: str, voter_count: int, *, api_kwargs: JSONDict = None):
super().__init__(api_kwargs=api_kwargs)
self.text = text
self.voter_count = voter_count
self.text: str = text
self.voter_count: int = voter_count
self._id_attrs = (self.text, self.voter_count)
@ -111,9 +111,9 @@ class PollAnswer(TelegramObject):
self, poll_id: str, user: User, option_ids: Sequence[int], *, api_kwargs: JSONDict = None
):
super().__init__(api_kwargs=api_kwargs)
self.poll_id = poll_id
self.user = user
self.option_ids = parse_sequence_arg(option_ids)
self.poll_id: str = poll_id
self.user: User = user
self.option_ids: Tuple[int, ...] = parse_sequence_arg(option_ids)
self._id_attrs = (self.poll_id, self.user, tuple(self.option_ids))
@ -244,19 +244,21 @@ class Poll(TelegramObject):
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.id = id # pylint: disable=invalid-name
self.question = question
self.options = parse_sequence_arg(options)
self.total_voter_count = total_voter_count
self.is_closed = is_closed
self.is_anonymous = is_anonymous
self.type = enum.get_member(constants.PollType, type, type)
self.allows_multiple_answers = allows_multiple_answers
self.correct_option_id = correct_option_id
self.explanation = explanation
self.explanation_entities = parse_sequence_arg(explanation_entities)
self.open_period = open_period
self.close_date = close_date
self.id: str = id # pylint: disable=invalid-name
self.question: str = question
self.options: Tuple[PollOption, ...] = parse_sequence_arg(options)
self.total_voter_count: int = total_voter_count
self.is_closed: bool = is_closed
self.is_anonymous: bool = is_anonymous
self.type: str = enum.get_member(constants.PollType, type, type)
self.allows_multiple_answers: bool = allows_multiple_answers
self.correct_option_id: Optional[int] = correct_option_id
self.explanation: Optional[str] = explanation
self.explanation_entities: Tuple[MessageEntity, ...] = parse_sequence_arg(
explanation_entities
)
self.open_period: Optional[int] = open_period
self.close_date: Optional[datetime.datetime] = close_date
self._id_attrs = (self.id,)

View file

@ -53,9 +53,9 @@ class ProximityAlertTriggered(TelegramObject):
self, traveler: User, watcher: User, distance: int, *, api_kwargs: JSONDict = None
):
super().__init__(api_kwargs=api_kwargs)
self.traveler = traveler
self.watcher = watcher
self.distance = distance
self.traveler: User = traveler
self.watcher: User = watcher
self.distance: int = distance
self._id_attrs = (self.traveler, self.watcher, self.distance)

View file

@ -18,7 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram ReplyKeyboardMarkup."""
from typing import ClassVar, Sequence, Union
from typing import ClassVar, Optional, Sequence, Tuple, Union
from telegram import constants
from telegram._keyboardbutton import KeyboardButton
@ -138,17 +138,17 @@ class ReplyKeyboardMarkup(TelegramObject):
)
# Required
self.keyboard = tuple(
self.keyboard: Tuple[Tuple[KeyboardButton, ...], ...] = tuple(
tuple(KeyboardButton(button) if isinstance(button, str) else button for button in row)
for row in keyboard
)
# Optionals
self.resize_keyboard = resize_keyboard
self.one_time_keyboard = one_time_keyboard
self.selective = selective
self.input_field_placeholder = input_field_placeholder
self.is_persistent = is_persistent
self.resize_keyboard: Optional[bool] = resize_keyboard
self.one_time_keyboard: Optional[bool] = one_time_keyboard
self.selective: Optional[bool] = selective
self.input_field_placeholder: Optional[str] = input_field_placeholder
self.is_persistent: Optional[bool] = is_persistent
self._id_attrs = (self.keyboard,)

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram ReplyKeyboardRemove."""
from typing import Optional
from telegram._telegramobject import TelegramObject
from telegram._utils.types import JSONDict
@ -64,8 +65,8 @@ class ReplyKeyboardRemove(TelegramObject):
def __init__(self, selective: bool = None, *, api_kwargs: JSONDict = None):
super().__init__(api_kwargs=api_kwargs)
# Required
self.remove_keyboard = True
self.remove_keyboard: bool = True
# Optionals
self.selective = selective
self.selective: Optional[bool] = selective
self._freeze()

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram Sent Web App Message."""
from typing import Optional
from telegram._telegramobject import TelegramObject
from telegram._utils.types import JSONDict
@ -46,7 +47,7 @@ class SentWebAppMessage(TelegramObject):
def __init__(self, inline_message_id: str = None, *, api_kwargs: JSONDict = None):
super().__init__(api_kwargs=api_kwargs)
# Optionals
self.inline_message_id = inline_message_id
self.inline_message_id: Optional[str] = inline_message_id
self._id_attrs = (self.inline_message_id,)

View file

@ -38,6 +38,7 @@ from typing import (
Type,
TypeVar,
Union,
cast,
)
from telegram._utils.datetime import to_timestamp
@ -259,7 +260,7 @@ class TelegramObject:
out["api_kwargs"] = dict(self.api_kwargs)
return out
def __setstate__(self, state: dict) -> None:
def __setstate__(self, state: Dict[str, object]) -> None:
"""
Overrides :meth:`object.__setstate__` to customize the unpickling process of objects of
this type. Modifies the object in-place.
@ -283,7 +284,7 @@ class TelegramObject:
setattr(self, "_bot", None)
# get api_kwargs first because we may need to add entries to it (see try-except below)
api_kwargs = state.pop("api_kwargs", {})
api_kwargs = cast(Dict[str, object], state.pop("api_kwargs", {}))
# get _frozen before the loop to avoid setting it to True in the loop
frozen = state.pop("_frozen", False)
@ -307,7 +308,7 @@ class TelegramObject:
if frozen:
self._freeze()
def __deepcopy__(self: Tele_co, memodict: dict) -> Tele_co:
def __deepcopy__(self: Tele_co, memodict: Dict[int, object]) -> Tele_co:
"""
Customizes how :func:`copy.deepcopy` processes objects of this type.
The only difference to the default implementation is that the :class:`telegram.Bot`

View file

@ -254,22 +254,22 @@ class Update(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.update_id = update_id
self.update_id: int = update_id
# Optionals
self.message = message
self.edited_message = edited_message
self.inline_query = inline_query
self.chosen_inline_result = chosen_inline_result
self.callback_query = callback_query
self.shipping_query = shipping_query
self.pre_checkout_query = pre_checkout_query
self.channel_post = channel_post
self.edited_channel_post = edited_channel_post
self.poll = poll
self.poll_answer = poll_answer
self.my_chat_member = my_chat_member
self.chat_member = chat_member
self.chat_join_request = chat_join_request
self.message: Optional[Message] = message
self.edited_message: Optional[Message] = edited_message
self.inline_query: Optional[InlineQuery] = inline_query
self.chosen_inline_result: Optional[ChosenInlineResult] = chosen_inline_result
self.callback_query: Optional[CallbackQuery] = callback_query
self.shipping_query: Optional[ShippingQuery] = shipping_query
self.pre_checkout_query: Optional[PreCheckoutQuery] = pre_checkout_query
self.channel_post: Optional[Message] = channel_post
self.edited_channel_post: Optional[Message] = edited_channel_post
self.poll: Optional[Poll] = poll
self.poll_answer: Optional[PollAnswer] = poll_answer
self.my_chat_member: Optional[ChatMemberUpdated] = my_chat_member
self.chat_member: Optional[ChatMemberUpdated] = chat_member
self.chat_join_request: Optional[ChatJoinRequest] = chat_join_request
self._effective_user: Optional["User"] = None
self._effective_chat: Optional["Chat"] = None

View file

@ -143,18 +143,18 @@ class User(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.id = id # pylint: disable=invalid-name
self.first_name = first_name
self.is_bot = is_bot
self.id: int = id # pylint: disable=invalid-name
self.first_name: str = first_name
self.is_bot: bool = is_bot
# Optionals
self.last_name = last_name
self.username = username
self.language_code = language_code
self.can_join_groups = can_join_groups
self.can_read_all_group_messages = can_read_all_group_messages
self.supports_inline_queries = supports_inline_queries
self.is_premium = is_premium
self.added_to_attachment_menu = added_to_attachment_menu
self.last_name: Optional[str] = last_name
self.username: Optional[str] = username
self.language_code: Optional[str] = language_code
self.can_join_groups: Optional[bool] = can_join_groups
self.can_read_all_group_messages: Optional[bool] = can_read_all_group_messages
self.supports_inline_queries: Optional[bool] = supports_inline_queries
self.is_premium: Optional[bool] = is_premium
self.added_to_attachment_menu: Optional[bool] = added_to_attachment_menu
self._id_attrs = (self.id,)

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram UserProfilePhotos."""
from typing import TYPE_CHECKING, Optional, Sequence
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from telegram._files.photosize import PhotoSize
from telegram._telegramobject import TelegramObject
@ -62,8 +62,8 @@ class UserProfilePhotos(TelegramObject):
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.total_count = total_count
self.photos = tuple(tuple(sizes) for sizes in photos)
self.total_count: int = total_count
self.photos: Tuple[Tuple[PhotoSize, ...], ...] = tuple(tuple(sizes) for sizes in photos)
self._id_attrs = (self.total_count, self.photos)

Some files were not shown because too many files have changed in this diff Show more