Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify type hints for Bot method & class parameters #3868

Merged
merged 16 commits into from Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 36 additions & 36 deletions telegram/_bot.py
Expand Up @@ -69,7 +69,6 @@
from telegram._files.document import Document
from telegram._files.file import File
from telegram._files.inputmedia import InputMedia
from telegram._files.inputsticker import InputSticker
from telegram._files.location import Location
from telegram._files.photosize import PhotoSize
from telegram._files.sticker import MaskPosition, Sticker, StickerSet
Expand All @@ -79,13 +78,10 @@
from telegram._files.voice import Voice
from telegram._forumtopic import ForumTopic
from telegram._games.gamehighscore import GameHighScore
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresultsbutton import InlineQueryResultsButton
from telegram._menubutton import MenuButton
from telegram._message import Message
from telegram._messageid import MessageId
from telegram._passport.passportelementerrors import PassportElementError
from telegram._payment.shippingoption import ShippingOption
from telegram._poll import Poll
from telegram._sentwebappmessage import SentWebAppMessage
from telegram._telegramobject import TelegramObject
Expand Down Expand Up @@ -115,14 +111,18 @@

if TYPE_CHECKING:
from telegram import (
InlineKeyboardMarkup,
InlineQueryResult,
InputFile,
InputMediaAudio,
InputMediaDocument,
InputMediaPhoto,
InputMediaVideo,
InputSticker,
LabeledPrice,
MessageEntity,
PassportElementError,
ShippingOption,
)

BT = TypeVar("BT", bound="Bot")
Expand Down Expand Up @@ -2154,7 +2154,7 @@ async def edit_message_live_location(
inline_message_id: Optional[str] = None,
latitude: Optional[float] = None,
longitude: Optional[float] = None,
reply_markup: Optional[InlineKeyboardMarkup] = None,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
horizontal_accuracy: Optional[float] = None,
heading: Optional[int] = None,
proximity_alert_radius: Optional[int] = None,
Expand Down Expand Up @@ -2247,7 +2247,7 @@ async def stop_message_live_location(
chat_id: Optional[Union[str, int]] = None,
message_id: Optional[int] = None,
inline_message_id: Optional[str] = None,
reply_markup: Optional[InlineKeyboardMarkup] = None,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down Expand Up @@ -2521,11 +2521,11 @@ async def send_contact(
@_log
async def send_game(
self,
chat_id: Union[int, str],
chat_id: int,
Bibo-Joshi marked this conversation as resolved.
Show resolved Hide resolved
game_short_name: str,
disable_notification: DVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[InlineKeyboardMarkup] = None,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
Expand All @@ -2539,7 +2539,7 @@ async def send_game(
"""Use this method to send a game.

Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat.
chat_id (:obj:`int`): Unique identifier for the target chat.
game_short_name (:obj:`str`): Short name of the game, serves as the unique identifier
for the game. Set up your games via `@BotFather <https://t.me/BotFather>`_.
disable_notification (:obj:`bool`, optional): |disable_notification|
Expand Down Expand Up @@ -2826,7 +2826,7 @@ async def answer_inline_query(
@_log
async def get_user_profile_photos(
self,
user_id: Union[str, int],
user_id: int,
Bibo-Joshi marked this conversation as resolved.
Show resolved Hide resolved
offset: Optional[int] = None,
limit: Optional[int] = None,
*,
Expand Down Expand Up @@ -2938,7 +2938,7 @@ async def get_file(
async def ban_chat_member(
self,
chat_id: Union[str, int],
user_id: Union[str, int],
user_id: int,
until_date: Optional[Union[int, datetime]] = None,
revoke_messages: Optional[bool] = None,
*,
Expand Down Expand Up @@ -3046,7 +3046,7 @@ async def ban_chat_sender_chat(
async def unban_chat_member(
self,
chat_id: Union[str, int],
user_id: Union[str, int],
user_id: int,
only_if_banned: Optional[bool] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down Expand Up @@ -3203,7 +3203,7 @@ async def edit_message_text(
inline_message_id: Optional[str] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_web_page_preview: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional[InlineKeyboardMarkup] = None,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
entities: Optional[Sequence["MessageEntity"]] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down Expand Up @@ -3279,7 +3279,7 @@ async def edit_message_caption(
message_id: Optional[int] = None,
inline_message_id: Optional[str] = None,
caption: Optional[str] = None,
reply_markup: Optional[InlineKeyboardMarkup] = None,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
*,
Expand Down Expand Up @@ -3349,7 +3349,7 @@ async def edit_message_media(
chat_id: Optional[Union[str, int]] = None,
message_id: Optional[int] = None,
inline_message_id: Optional[str] = None,
reply_markup: Optional[InlineKeyboardMarkup] = None,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down Expand Up @@ -3876,7 +3876,7 @@ async def get_chat_member_count(
async def get_chat_member(
self,
chat_id: Union[str, int],
user_id: Union[str, int],
user_id: int,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down Expand Up @@ -4011,9 +4011,9 @@ async def get_webhook_info(
@_log
async def set_game_score(
self,
user_id: Union[int, str],
user_id: int,
score: int,
chat_id: Optional[Union[str, int]] = None,
chat_id: Optional[int] = None,
message_id: Optional[int] = None,
inline_message_id: Optional[str] = None,
force: Optional[bool] = None,
Expand All @@ -4037,7 +4037,7 @@ async def set_game_score(
decrease. This can be useful when fixing mistakes or banning cheaters.
disable_edit_message (:obj:`bool`, optional): Pass :obj:`True`, if the game message
should not be automatically edited to include the current scoreboard.
chat_id (:obj:`int` | :obj:`str`, optional): Required if :paramref:`inline_message_id`
chat_id (:obj:`int`, optional): Required if :paramref:`inline_message_id`
is not specified. Unique identifier for the target chat.
message_id (:obj:`int`, optional): Required if :paramref:`inline_message_id` is not
specified. Identifier of the sent message.
Expand Down Expand Up @@ -4076,8 +4076,8 @@ async def set_game_score(
@_log
async def get_game_high_scores(
self,
user_id: Union[int, str],
chat_id: Optional[Union[str, int]] = None,
user_id: int,
chat_id: Optional[int] = None,
message_id: Optional[int] = None,
inline_message_id: Optional[str] = None,
*,
Expand All @@ -4101,7 +4101,7 @@ async def get_game_high_scores(

Args:
user_id (:obj:`int`): Target user id.
chat_id (:obj:`int` | :obj:`str`, optional): Required if :paramref:`inline_message_id`
chat_id (:obj:`int`, optional): Required if :paramref:`inline_message_id`
is not specified. Unique identifier for the target chat.
message_id (:obj:`int`, optional): Required if :paramref:`inline_message_id` is not
specified. Identifier of the sent message.
Expand Down Expand Up @@ -4156,7 +4156,7 @@ async def send_invoice(
is_flexible: Optional[bool] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[InlineKeyboardMarkup] = None,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
provider_data: Optional[Union[str, object]] = None,
send_phone_number_to_provider: Optional[bool] = None,
send_email_to_provider: Optional[bool] = None,
Expand Down Expand Up @@ -4321,7 +4321,7 @@ async def answer_shipping_query(
self,
shipping_query_id: str,
ok: bool,
shipping_options: Optional[Sequence[ShippingOption]] = None,
shipping_options: Optional[Sequence["ShippingOption"]] = None,
error_message: Optional[str] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down Expand Up @@ -4483,7 +4483,7 @@ async def answer_web_app_query(
async def restrict_chat_member(
self,
chat_id: Union[str, int],
user_id: Union[str, int],
user_id: int,
permissions: ChatPermissions,
until_date: Optional[Union[int, datetime]] = None,
use_independent_chat_permissions: Optional[bool] = None,
Expand Down Expand Up @@ -4557,7 +4557,7 @@ async def restrict_chat_member(
async def promote_chat_member(
self,
chat_id: Union[str, int],
user_id: Union[str, int],
user_id: int,
can_change_info: Optional[bool] = None,
can_post_messages: Optional[bool] = None,
can_edit_messages: Optional[bool] = None,
Expand Down Expand Up @@ -4723,7 +4723,7 @@ async def set_chat_permissions(
async def set_chat_administrator_custom_title(
self,
chat_id: Union[int, str],
user_id: Union[int, str],
user_id: int,
custom_title: str,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down Expand Up @@ -5478,7 +5478,7 @@ async def get_custom_emoji_stickers(
@_log
async def upload_sticker_file(
self,
user_id: Union[str, int],
user_id: int,
sticker: Optional[FileInput],
sticker_format: Optional[str],
*,
Expand Down Expand Up @@ -5538,9 +5538,9 @@ async def upload_sticker_file(
@_log
async def add_sticker_to_set(
self,
user_id: Union[str, int],
user_id: int,
name: str,
sticker: Optional[InputSticker],
sticker: Optional["InputSticker"],
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = 20,
Expand Down Expand Up @@ -5636,10 +5636,10 @@ async def set_sticker_position_in_set(
@_log
async def create_new_sticker_set(
self,
user_id: Union[str, int],
user_id: int,
name: str,
title: str,
stickers: Optional[Sequence[InputSticker]],
stickers: Optional[Sequence["InputSticker"]],
sticker_format: Optional[str],
sticker_type: Optional[str] = None,
needs_repainting: Optional[bool] = None,
Expand Down Expand Up @@ -5807,7 +5807,7 @@ async def delete_sticker_set(
async def set_sticker_set_thumbnail(
self,
name: str,
user_id: Union[str, int],
user_id: int,
thumbnail: Optional[FileInput] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down Expand Up @@ -6079,8 +6079,8 @@ async def set_custom_emoji_sticker_set_thumbnail(
@_log
async def set_passport_data_errors(
self,
user_id: Union[str, int],
errors: Sequence[PassportElementError],
user_id: int,
errors: Sequence["PassportElementError"],
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down Expand Up @@ -6262,7 +6262,7 @@ async def stop_poll(
self,
chat_id: Union[int, str],
message_id: int,
reply_markup: Optional[InlineKeyboardMarkup] = None,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down
4 changes: 2 additions & 2 deletions telegram/_callbackquery.py
Expand Up @@ -531,7 +531,7 @@ async def stop_message_live_location(

async def set_game_score(
self,
user_id: Union[int, str],
user_id: int,
score: int,
force: Optional[bool] = None,
disable_edit_message: Optional[bool] = None,
Expand Down Expand Up @@ -589,7 +589,7 @@ async def set_game_score(

async def get_game_high_scores(
self,
user_id: Union[int, str],
user_id: int,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down
10 changes: 5 additions & 5 deletions telegram/_chat.py
Expand Up @@ -677,7 +677,7 @@ async def get_member_count(

async def get_member(
self,
user_id: Union[str, int],
user_id: int,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down Expand Up @@ -707,7 +707,7 @@ async def get_member(

async def ban_member(
self,
user_id: Union[str, int],
user_id: int,
revoke_messages: Optional[bool] = None,
until_date: Optional[Union[int, datetime]] = None,
*,
Expand Down Expand Up @@ -877,7 +877,7 @@ async def unban_chat(

async def unban_member(
self,
user_id: Union[str, int],
user_id: int,
only_if_banned: Optional[bool] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down Expand Up @@ -909,7 +909,7 @@ async def unban_member(

async def promote_member(
self,
user_id: Union[str, int],
user_id: int,
can_change_info: Optional[bool] = None,
can_post_messages: Optional[bool] = None,
can_edit_messages: Optional[bool] = None,
Expand Down Expand Up @@ -970,7 +970,7 @@ async def promote_member(

async def restrict_member(
self,
user_id: Union[str, int],
user_id: int,
permissions: ChatPermissions,
until_date: Optional[Union[int, datetime]] = None,
use_independent_chat_permissions: Optional[bool] = None,
Expand Down
4 changes: 2 additions & 2 deletions telegram/_loginurl.py
Expand Up @@ -86,7 +86,7 @@ class LoginUrl(TelegramObject):
def __init__(
self,
url: str,
forward_text: Optional[bool] = None,
forward_text: Optional[str] = None,
bot_username: Optional[str] = None,
request_write_access: Optional[bool] = None,
*,
Expand All @@ -96,7 +96,7 @@ def __init__(
# Required
self.url: str = url
# Optional
self.forward_text: Optional[bool] = forward_text
self.forward_text: Optional[str] = forward_text
self.bot_username: Optional[str] = bot_username
self.request_write_access: Optional[bool] = request_write_access

Expand Down