Skip to content

Commit

Permalink
Improve Type Hinting for Arguments with Default Values in Bot (#3942)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshil21 committed Oct 25, 2023
1 parent 300ec92 commit cbe808e
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 136 deletions.
43 changes: 18 additions & 25 deletions telegram/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,7 @@
from telegram._utils.files import is_local_file, parse_file_input
from telegram._utils.logging import get_logger
from telegram._utils.repr import build_repr_with_selected_attrs
from telegram._utils.types import (
CorrectOptionID,
DVInput,
FileInput,
JSONDict,
ODVInput,
ReplyMarkup,
)
from telegram._utils.types import CorrectOptionID, FileInput, JSONDict, ODVInput, ReplyMarkup
from telegram._utils.warnings import warn
from telegram._webhookinfo import WebhookInfo
from telegram.constants import InlineQueryLimit
Expand Down Expand Up @@ -798,7 +791,7 @@ async def send_message(
parse_mode: ODVInput[str] = DEFAULT_NONE,
entities: Optional[Sequence["MessageEntity"]] = None,
disable_web_page_preview: ODVInput[bool] = DEFAULT_NONE,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
Expand Down Expand Up @@ -933,7 +926,7 @@ async def forward_message(
chat_id: Union[int, str],
from_chat_id: Union[str, int],
message_id: int,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
*,
Expand Down Expand Up @@ -999,7 +992,7 @@ async def send_photo(
chat_id: Union[int, str],
photo: Union[FileInput, "PhotoSize"],
caption: Optional[str] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
Expand Down Expand Up @@ -1113,7 +1106,7 @@ async def send_audio(
performer: Optional[str] = None,
title: Optional[str] = None,
caption: Optional[str] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
Expand Down Expand Up @@ -1237,7 +1230,7 @@ async def send_document(
chat_id: Union[int, str],
document: Union[FileInput, "Document"],
caption: Optional[str] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
Expand Down Expand Up @@ -1356,7 +1349,7 @@ async def send_sticker(
self,
chat_id: Union[int, str],
sticker: Union[FileInput, "Sticker"],
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
Expand Down Expand Up @@ -1444,7 +1437,7 @@ async def send_video(
video: Union[FileInput, "Video"],
duration: Optional[int] = None,
caption: Optional[str] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
width: Optional[int] = None,
Expand Down Expand Up @@ -1583,7 +1576,7 @@ async def send_video_note(
video_note: Union[FileInput, "VideoNote"],
duration: Optional[int] = None,
length: Optional[int] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
Expand Down Expand Up @@ -1698,7 +1691,7 @@ async def send_animation(
height: Optional[int] = None,
caption: Optional[str] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
Expand Down Expand Up @@ -1826,7 +1819,7 @@ async def send_voice(
voice: Union[FileInput, "Voice"],
duration: Optional[int] = None,
caption: Optional[str] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
Expand Down Expand Up @@ -2070,7 +2063,7 @@ async def send_location(
chat_id: Union[int, str],
latitude: Optional[float] = None,
longitude: Optional[float] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
live_period: Optional[int] = None,
Expand Down Expand Up @@ -2331,7 +2324,7 @@ async def send_venue(
title: Optional[str] = None,
address: Optional[str] = None,
foursquare_id: Optional[str] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
foursquare_type: Optional[str] = None,
Expand Down Expand Up @@ -2455,7 +2448,7 @@ async def send_contact(
phone_number: Optional[str] = None,
first_name: Optional[str] = None,
last_name: Optional[str] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
vcard: Optional[str] = None,
Expand Down Expand Up @@ -2556,7 +2549,7 @@ async def send_game(
self,
chat_id: int,
game_short_name: str,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
Expand Down Expand Up @@ -4187,7 +4180,7 @@ async def send_invoice(
need_email: Optional[bool] = None,
need_shipping_address: Optional[bool] = None,
is_flexible: Optional[bool] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
provider_data: Optional[Union[str, object]] = None,
Expand Down Expand Up @@ -6760,9 +6753,9 @@ async def copy_message(
caption: Optional[str] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: DVInput[bool] = DEFAULT_NONE,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional[ReplyMarkup] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
Expand Down
6 changes: 3 additions & 3 deletions telegram/_callbackquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from telegram._telegramobject import TelegramObject
from telegram._user import User
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import DVInput, JSONDict, ODVInput, ReplyMarkup
from telegram._utils.types import JSONDict, ODVInput, ReplyMarkup

if TYPE_CHECKING:
from telegram import (
Expand Down Expand Up @@ -725,9 +725,9 @@ async def copy_message(
caption: Optional[str] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: DVInput[bool] = DEFAULT_NONE,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional[ReplyMarkup] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
Expand Down
49 changes: 21 additions & 28 deletions telegram/_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,7 @@
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import (
CorrectOptionID,
DVInput,
FileInput,
JSONDict,
ODVInput,
ReplyMarkup,
)
from telegram._utils.types import CorrectOptionID, FileInput, JSONDict, ODVInput, ReplyMarkup
from telegram.helpers import escape_markdown
from telegram.helpers import mention_html as helpers_mention_html
from telegram.helpers import mention_markdown as helpers_mention_markdown
Expand Down Expand Up @@ -1326,7 +1319,7 @@ async def send_message(
text: str,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_web_page_preview: ODVInput[bool] = DEFAULT_NONE,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
Expand Down Expand Up @@ -1457,7 +1450,7 @@ async def send_photo(
self,
photo: Union[FileInput, "PhotoSize"],
caption: Optional[str] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
Expand Down Expand Up @@ -1510,7 +1503,7 @@ async def send_contact(
phone_number: Optional[str] = None,
first_name: Optional[str] = None,
last_name: Optional[str] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
vcard: Optional[str] = None,
Expand Down Expand Up @@ -1562,7 +1555,7 @@ async def send_audio(
performer: Optional[str] = None,
title: Optional[str] = None,
caption: Optional[str] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
Expand Down Expand Up @@ -1617,7 +1610,7 @@ async def send_document(
self,
document: Union[FileInput, "Document"],
caption: Optional[str] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
Expand Down Expand Up @@ -1712,7 +1705,7 @@ async def send_dice(
async def send_game(
self,
game_short_name: str,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
Expand Down Expand Up @@ -1769,7 +1762,7 @@ async def send_invoice(
need_email: Optional[bool] = None,
need_shipping_address: Optional[bool] = None,
is_flexible: Optional[bool] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
provider_data: Optional[Union[str, object]] = None,
Expand Down Expand Up @@ -1847,7 +1840,7 @@ async def send_location(
self,
latitude: Optional[float] = None,
longitude: Optional[float] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
live_period: Optional[int] = None,
Expand Down Expand Up @@ -1905,7 +1898,7 @@ async def send_animation(
height: Optional[int] = None,
caption: Optional[str] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
Expand Down Expand Up @@ -1960,7 +1953,7 @@ async def send_animation(
async def send_sticker(
self,
sticker: Union[FileInput, "Sticker"],
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
Expand Down Expand Up @@ -2008,7 +2001,7 @@ async def send_venue(
title: Optional[str] = None,
address: Optional[str] = None,
foursquare_id: Optional[str] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
foursquare_type: Optional[str] = None,
Expand Down Expand Up @@ -2064,7 +2057,7 @@ async def send_video(
video: Union[FileInput, "Video"],
duration: Optional[int] = None,
caption: Optional[str] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
width: Optional[int] = None,
Expand Down Expand Up @@ -2126,7 +2119,7 @@ async def send_video_note(
video_note: Union[FileInput, "VideoNote"],
duration: Optional[int] = None,
length: Optional[int] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
Expand Down Expand Up @@ -2176,7 +2169,7 @@ async def send_voice(
voice: Union[FileInput, "Voice"],
duration: Optional[int] = None,
caption: Optional[str] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
Expand Down Expand Up @@ -2294,9 +2287,9 @@ async def send_copy(
caption: Optional[str] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: DVInput[bool] = DEFAULT_NONE,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional[ReplyMarkup] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
Expand Down Expand Up @@ -2344,9 +2337,9 @@ async def copy_message(
caption: Optional[str] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: DVInput[bool] = DEFAULT_NONE,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional[ReplyMarkup] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
Expand Down Expand Up @@ -2391,7 +2384,7 @@ async def forward_from(
self,
from_chat_id: Union[str, int],
message_id: int,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
*,
Expand Down Expand Up @@ -2433,7 +2426,7 @@ async def forward_to(
self,
chat_id: Union[int, str],
message_id: int,
disable_notification: DVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
*,
Expand Down

0 comments on commit cbe808e

Please sign in to comment.