From 66b6d3c4971d5c18dac8d8d1362db9c3f7292197 Mon Sep 17 00:00:00 2001 From: Bibo-Joshi <22366557+Bibo-Joshi@users.noreply.github.com> Date: Sun, 7 May 2023 14:10:20 +0200 Subject: [PATCH] Recover 100% Type Completeness (#3676) --- .github/workflows/type_completeness.yml | 18 +++++++++--------- telegram/_bot.py | 4 ++-- telegram/_botdescription.py | 4 ++-- telegram/_botname.py | 2 +- telegram/_switchinlinequerychosenchat.py | 11 ++++++----- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/.github/workflows/type_completeness.yml b/.github/workflows/type_completeness.yml index e5ef12ba3..4dbd58e63 100644 --- a/.github/workflows/type_completeness.yml +++ b/.github/workflows/type_completeness.yml @@ -49,21 +49,21 @@ jobs: pr = float( json.load(open("pr.json", "rb"))["typeCompleteness"]["completenessScore"] ) - base_text = f"After this PR, type completeness will be {round(pr, 3)}." - if pr < (base - 0.1): - text = f"This PR decreases type completeness by {round(base - pr, 3)}. ❌" + base_text = f"This PR changes type completeness from {round(base, 3)} to {round(pr, 3)}." + if pr < (base - 0.001): + text = f"{base_text} ❌" set_summary(text) print(Path("pr.readable").read_text(encoding="utf-8")) - error(f"{text}\n{base_text}") + error(text) exit(1) - elif pr > (base + 0.1): - text = f"This PR increases type completeness by {round(pr - base, 3)}. ✨" + elif pr > (base + 0.001): + text = f"{base_text} ✨" set_summary(text) if pr < 1: print(Path("pr.readable").read_text(encoding="utf-8")) - print(f"{text}\n{base_text}") + print(text) else: - text = f"This PR does not change type completeness by more than 0.1. ✅" + text = f"{base_text} This is less than 0.1 percentage points. ✅" set_summary(text) print(Path("pr.readable").read_text(encoding="utf-8")) - print(f"{text}\n{base_text}") + print(text) diff --git a/telegram/_bot.py b/telegram/_bot.py index b2aa643d6..6cfb63672 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -244,7 +244,7 @@ class Bot(TelegramObject, AsyncContextManager["Bot"]): self._local_mode: bool = local_mode self._bot_user: Optional[User] = None self._private_key: Optional[bytes] = None - self._initialized = False + self._initialized: bool = False self._request: Tuple[BaseRequest, BaseRequest] = ( HTTPXRequest() if get_updates_request is None else get_updates_request, @@ -375,7 +375,7 @@ class Bot(TelegramObject, AsyncContextManager["Bot"]): # consider adding Paramspec from typing_extensions to properly fix this. Currently a workaround def _log(func: Any): # type: ignore[no-untyped-def] # skipcq: PY-D0003 @functools.wraps(func) - async def decorator(self, *args, **kwargs): # type: ignore[no-untyped-def] + async def decorator(self: "Bot", *args: Any, **kwargs: Any) -> Any: # pylint: disable=protected-access self._LOGGER.debug("Entering: %s", func.__name__) result = await func(self, *args, **kwargs) # skipcq: PYL-E1102 diff --git a/telegram/_botdescription.py b/telegram/_botdescription.py index e14ef3234..77388824f 100644 --- a/telegram/_botdescription.py +++ b/telegram/_botdescription.py @@ -41,7 +41,7 @@ class BotDescription(TelegramObject): def __init__(self, description: str, *, api_kwargs: JSONDict = None): super().__init__(api_kwargs=api_kwargs) - self.description = description + self.description: str = description self._id_attrs = (self.description,) @@ -68,7 +68,7 @@ class BotShortDescription(TelegramObject): def __init__(self, short_description: str, *, api_kwargs: JSONDict = None): super().__init__(api_kwargs=api_kwargs) - self.short_description = short_description + self.short_description: str = short_description self._id_attrs = (self.short_description,) diff --git a/telegram/_botname.py b/telegram/_botname.py index 05c0610db..6e69f3908 100644 --- a/telegram/_botname.py +++ b/telegram/_botname.py @@ -44,7 +44,7 @@ class BotName(TelegramObject): def __init__(self, name: str, *, api_kwargs: JSONDict = None): super().__init__(api_kwargs=api_kwargs) - self.name = name + self.name: str = name self._id_attrs = (self.name,) diff --git a/telegram/_switchinlinequerychosenchat.py b/telegram/_switchinlinequerychosenchat.py index 459b30abf..206405f7d 100644 --- a/telegram/_switchinlinequerychosenchat.py +++ b/telegram/_switchinlinequerychosenchat.py @@ -16,6 +16,7 @@ # # You should have received a copy of the GNU Lesser Public License """This module contains a class that represents a Telegram SwitchInlineQueryChosenChat.""" +from typing import Optional from telegram._telegramobject import TelegramObject from telegram._utils.types import JSONDict @@ -82,11 +83,11 @@ class SwitchInlineQueryChosenChat(TelegramObject): ): super().__init__(api_kwargs=api_kwargs) # Optional - self.query = query - self.allow_user_chats = allow_user_chats - self.allow_bot_chats = allow_bot_chats - self.allow_group_chats = allow_group_chats - self.allow_channel_chats = allow_channel_chats + self.query: Optional[str] = query + self.allow_user_chats: Optional[bool] = allow_user_chats + self.allow_bot_chats: Optional[bool] = allow_bot_chats + self.allow_group_chats: Optional[bool] = allow_group_chats + self.allow_channel_chats: Optional[bool] = allow_channel_chats self._id_attrs = ( self.query,