From f3bd0f1462f4950b4024ad0c4bca6d30168ddad2 Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Sun, 12 May 2024 03:13:20 -0400 Subject: [PATCH] Add New Rules to `ruff` Config (#4250) --- pyproject.toml | 8 ++++--- telegram/_bot.py | 2 +- telegram/_message.py | 2 +- .../_passport/encryptedpassportelement.py | 5 ++++- telegram/ext/_aioratelimiter.py | 2 +- telegram/ext/_basepersistence.py | 2 +- telegram/ext/_baseupdateprocessor.py | 2 +- telegram/ext/_callbackcontext.py | 6 ++--- telegram/ext/_defaults.py | 20 ++++++++--------- .../ext/_handlers/callbackqueryhandler.py | 4 ++-- .../_handlers/choseninlineresulthandler.py | 4 ++-- telegram/ext/_handlers/commandhandler.py | 4 ++-- telegram/ext/_handlers/conversationhandler.py | 22 +++++++++---------- telegram/ext/_handlers/inlinequeryhandler.py | 4 ++-- telegram/ext/_handlers/messagehandler.py | 4 ++-- telegram/ext/_handlers/prefixhandler.py | 4 ++-- .../ext/_handlers/stringcommandhandler.py | 4 ++-- telegram/ext/_handlers/stringregexhandler.py | 4 ++-- telegram/ext/filters.py | 10 ++++----- 19 files changed, 59 insertions(+), 54 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index cd69c7578..b02870776 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,13 +20,15 @@ explicit-preview-rules = true ignore = ["PLR2004", "PLR0911", "PLR0912", "PLR0913", "PLR0915", "PERF203"] select = ["E", "F", "I", "PL", "UP", "RUF", "PTH", "C4", "B", "PIE", "SIM", "RET", "RSE", "G", "ISC", "PT", "ASYNC", "TCH", "SLOT", "PERF", "PYI", "FLY", "AIR", "RUF022", - "RUF023", "Q", "INP", "W"] + "RUF023", "Q", "INP", "W", "YTT", "DTZ", "ARG"] # Add "FURB" after it's out of preview +# Add "A (flake8-builtins)" after we drop pylint [tool.ruff.lint.per-file-ignores] "tests/*.py" = ["B018"] -"tests/**.py" = ["RUF012", "ASYNC101"] -"docs/**.py" = ["INP001"] +"tests/**.py" = ["RUF012", "ASYNC101", "DTZ", "ARG"] +"docs/**.py" = ["INP001", "ARG"] +"examples/**.py" = ["ARG"] # PYLINT: [tool.pylint."messages control"] diff --git a/telegram/_bot.py b/telegram/_bot.py index b7198c50d..e44a3a096 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -8850,7 +8850,7 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified. api_kwargs=api_kwargs, ) - def to_dict(self, recursive: bool = True) -> JSONDict: + def to_dict(self, recursive: bool = True) -> JSONDict: # noqa: ARG002 """See :meth:`telegram.TelegramObject.to_dict`.""" data: JSONDict = {"id": self.id, "username": self.username, "first_name": self.first_name} diff --git a/telegram/_message.py b/telegram/_message.py index 87ecdd300..60fe96c0c 100644 --- a/telegram/_message.py +++ b/telegram/_message.py @@ -198,7 +198,7 @@ class MaybeInaccessibleMessage(TelegramObject): data["date"] = from_timestamp(data["date"], tzinfo=loc_tzinfo) data["chat"] = Chat.de_json(data.get("chat"), bot) - return super()._de_json(data=data, bot=bot) + return super()._de_json(data=data, bot=bot, api_kwargs=api_kwargs) class InaccessibleMessage(MaybeInaccessibleMessage): diff --git a/telegram/_passport/encryptedpassportelement.py b/telegram/_passport/encryptedpassportelement.py index e6a22ee2e..f0d869fe2 100644 --- a/telegram/_passport/encryptedpassportelement.py +++ b/telegram/_passport/encryptedpassportelement.py @@ -157,7 +157,10 @@ class EncryptedPassportElement(TelegramObject): reverse_side: Optional[PassportFile] = None, selfie: Optional[PassportFile] = None, translation: Optional[Sequence[PassportFile]] = None, - credentials: Optional["Credentials"] = None, # pylint: disable=unused-argument + # TODO: Remove the credentials argument in 22.0 or later + credentials: Optional[ # pylint: disable=unused-argument # noqa: ARG002 + "Credentials" + ] = None, *, api_kwargs: Optional[JSONDict] = None, ): diff --git a/telegram/ext/_aioratelimiter.py b/telegram/ext/_aioratelimiter.py index ac9c4f3f7..714bbc63f 100644 --- a/telegram/ext/_aioratelimiter.py +++ b/telegram/ext/_aioratelimiter.py @@ -208,7 +208,7 @@ class AIORateLimiter(BaseRateLimiter[int]): callback: Callable[..., Coroutine[Any, Any, Union[bool, JSONDict, List[JSONDict]]]], args: Any, kwargs: Dict[str, Any], - endpoint: str, + endpoint: str, # noqa: ARG002 data: Dict[str, Any], rate_limit_args: Optional[int], ) -> Union[bool, JSONDict, List[JSONDict]]: diff --git a/telegram/ext/_basepersistence.py b/telegram/ext/_basepersistence.py index dafd35234..5199a165b 100644 --- a/telegram/ext/_basepersistence.py +++ b/telegram/ext/_basepersistence.py @@ -163,7 +163,7 @@ class BasePersistence(Generic[UD, CD, BD], ABC): return self._update_interval @update_interval.setter - def update_interval(self, value: object) -> NoReturn: + def update_interval(self, _: object) -> NoReturn: raise AttributeError( "You can not assign a new value to update_interval after initialization." ) diff --git a/telegram/ext/_baseupdateprocessor.py b/telegram/ext/_baseupdateprocessor.py index 7bcca890e..89d51d96f 100644 --- a/telegram/ext/_baseupdateprocessor.py +++ b/telegram/ext/_baseupdateprocessor.py @@ -165,7 +165,7 @@ class SimpleUpdateProcessor(BaseUpdateProcessor): async def do_process_update( self, - update: object, + update: object, # noqa: ARG002 coroutine: "Awaitable[Any]", ) -> None: """Immediately awaits the coroutine, i.e. does not apply any additional processing. diff --git a/telegram/ext/_callbackcontext.py b/telegram/ext/_callbackcontext.py index 65abe7d52..92113bae9 100644 --- a/telegram/ext/_callbackcontext.py +++ b/telegram/ext/_callbackcontext.py @@ -165,7 +165,7 @@ class CallbackContext(Generic[BT, UD, CD, BD]): return self.application.bot_data @bot_data.setter - def bot_data(self, value: object) -> NoReturn: + def bot_data(self, _: object) -> NoReturn: raise AttributeError( f"You can not assign a new value to bot_data, see {_STORING_DATA_WIKI}" ) @@ -192,7 +192,7 @@ class CallbackContext(Generic[BT, UD, CD, BD]): return None @chat_data.setter - def chat_data(self, value: object) -> NoReturn: + def chat_data(self, _: object) -> NoReturn: raise AttributeError( f"You can not assign a new value to chat_data, see {_STORING_DATA_WIKI}" ) @@ -214,7 +214,7 @@ class CallbackContext(Generic[BT, UD, CD, BD]): return None @user_data.setter - def user_data(self, value: object) -> NoReturn: + def user_data(self, _: object) -> NoReturn: raise AttributeError( f"You can not assign a new value to user_data, see {_STORING_DATA_WIKI}" ) diff --git a/telegram/ext/_defaults.py b/telegram/ext/_defaults.py index f277a4b0e..02e7a1a16 100644 --- a/telegram/ext/_defaults.py +++ b/telegram/ext/_defaults.py @@ -235,7 +235,7 @@ class Defaults: return self._parse_mode @parse_mode.setter - def parse_mode(self, value: object) -> NoReturn: + def parse_mode(self, _: object) -> NoReturn: raise AttributeError("You can not assign a new value to parse_mode after initialization.") @property @@ -246,7 +246,7 @@ class Defaults: return self._parse_mode @explanation_parse_mode.setter - def explanation_parse_mode(self, value: object) -> NoReturn: + def explanation_parse_mode(self, _: object) -> NoReturn: raise AttributeError( "You can not assign a new value to explanation_parse_mode after initialization." ) @@ -259,7 +259,7 @@ class Defaults: return self._parse_mode @quote_parse_mode.setter - def quote_parse_mode(self, value: object) -> NoReturn: + def quote_parse_mode(self, _: object) -> NoReturn: raise AttributeError( "You can not assign a new value to quote_parse_mode after initialization." ) @@ -272,7 +272,7 @@ class Defaults: return self._disable_notification @disable_notification.setter - def disable_notification(self, value: object) -> NoReturn: + def disable_notification(self, _: object) -> NoReturn: raise AttributeError( "You can not assign a new value to disable_notification after initialization." ) @@ -289,7 +289,7 @@ class Defaults: return self._link_preview_options.is_disabled if self._link_preview_options else None @disable_web_page_preview.setter - def disable_web_page_preview(self, value: object) -> NoReturn: + def disable_web_page_preview(self, _: object) -> NoReturn: raise AttributeError( "You can not assign a new value to disable_web_page_preview after initialization." ) @@ -302,7 +302,7 @@ class Defaults: return self._allow_sending_without_reply @allow_sending_without_reply.setter - def allow_sending_without_reply(self, value: object) -> NoReturn: + def allow_sending_without_reply(self, _: object) -> NoReturn: raise AttributeError( "You can not assign a new value to allow_sending_without_reply after initialization." ) @@ -318,7 +318,7 @@ class Defaults: return self._do_quote if self._do_quote is not None else None @quote.setter - def quote(self, value: object) -> NoReturn: + def quote(self, _: object) -> NoReturn: raise AttributeError("You can not assign a new value to quote after initialization.") @property @@ -329,7 +329,7 @@ class Defaults: return self._tzinfo @tzinfo.setter - def tzinfo(self, value: object) -> NoReturn: + def tzinfo(self, _: object) -> NoReturn: raise AttributeError("You can not assign a new value to tzinfo after initialization.") @property @@ -341,7 +341,7 @@ class Defaults: return self._block @block.setter - def block(self, value: object) -> NoReturn: + def block(self, _: object) -> NoReturn: raise AttributeError("You can not assign a new value to block after initialization.") @property @@ -354,7 +354,7 @@ class Defaults: return self._protect_content @protect_content.setter - def protect_content(self, value: object) -> NoReturn: + def protect_content(self, _: object) -> NoReturn: raise AttributeError( "You can't assign a new value to protect_content after initialization." ) diff --git a/telegram/ext/_handlers/callbackqueryhandler.py b/telegram/ext/_handlers/callbackqueryhandler.py index 2fb79b567..afd648879 100644 --- a/telegram/ext/_handlers/callbackqueryhandler.py +++ b/telegram/ext/_handlers/callbackqueryhandler.py @@ -159,8 +159,8 @@ class CallbackQueryHandler(BaseHandler[Update, CCT]): def collect_additional_context( self, context: CCT, - update: Update, - application: "Application[Any, CCT, Any, Any, Any, Any]", + update: Update, # noqa: ARG002 + application: "Application[Any, CCT, Any, Any, Any, Any]", # noqa: ARG002 check_result: Union[bool, Match[str]], ) -> None: """Add the result of ``re.match(pattern, update.callback_query.data)`` to diff --git a/telegram/ext/_handlers/choseninlineresulthandler.py b/telegram/ext/_handlers/choseninlineresulthandler.py index 9191ad250..db7a87214 100644 --- a/telegram/ext/_handlers/choseninlineresulthandler.py +++ b/telegram/ext/_handlers/choseninlineresulthandler.py @@ -109,8 +109,8 @@ class ChosenInlineResultHandler(BaseHandler[Update, CCT]): def collect_additional_context( self, context: CCT, - update: Update, - application: "Application[Any, CCT, Any, Any, Any, Any]", + update: Update, # noqa: ARG002 + application: "Application[Any, CCT, Any, Any, Any, Any]", # noqa: ARG002 check_result: Union[bool, Match[str]], ) -> None: """This function adds the matched regex pattern result to diff --git a/telegram/ext/_handlers/commandhandler.py b/telegram/ext/_handlers/commandhandler.py index 814e19660..edad3963a 100644 --- a/telegram/ext/_handlers/commandhandler.py +++ b/telegram/ext/_handlers/commandhandler.py @@ -204,8 +204,8 @@ class CommandHandler(BaseHandler[Update, CCT]): def collect_additional_context( self, context: CCT, - update: Update, - application: "Application[Any, CCT, Any, Any, Any, Any]", + update: Update, # noqa: ARG002 + application: "Application[Any, CCT, Any, Any, Any, Any]", # noqa: ARG002 check_result: Optional[Union[bool, Tuple[List[str], Optional[bool]]]], ) -> None: """Add text after the command to :attr:`CallbackContext.args` as list, split on single diff --git a/telegram/ext/_handlers/conversationhandler.py b/telegram/ext/_handlers/conversationhandler.py index 3c7dcc767..f3fad9f83 100644 --- a/telegram/ext/_handlers/conversationhandler.py +++ b/telegram/ext/_handlers/conversationhandler.py @@ -473,7 +473,7 @@ class ConversationHandler(BaseHandler[Update, CCT]): return self._entry_points @entry_points.setter - def entry_points(self, value: object) -> NoReturn: + def entry_points(self, _: object) -> NoReturn: raise AttributeError( "You can not assign a new value to entry_points after initialization." ) @@ -487,7 +487,7 @@ class ConversationHandler(BaseHandler[Update, CCT]): return self._states @states.setter - def states(self, value: object) -> NoReturn: + def states(self, _: object) -> NoReturn: raise AttributeError("You can not assign a new value to states after initialization.") @property @@ -499,7 +499,7 @@ class ConversationHandler(BaseHandler[Update, CCT]): return self._fallbacks @fallbacks.setter - def fallbacks(self, value: object) -> NoReturn: + def fallbacks(self, _: object) -> NoReturn: raise AttributeError("You can not assign a new value to fallbacks after initialization.") @property @@ -508,7 +508,7 @@ class ConversationHandler(BaseHandler[Update, CCT]): return self._allow_reentry @allow_reentry.setter - def allow_reentry(self, value: object) -> NoReturn: + def allow_reentry(self, _: object) -> NoReturn: raise AttributeError( "You can not assign a new value to allow_reentry after initialization." ) @@ -519,7 +519,7 @@ class ConversationHandler(BaseHandler[Update, CCT]): return self._per_user @per_user.setter - def per_user(self, value: object) -> NoReturn: + def per_user(self, _: object) -> NoReturn: raise AttributeError("You can not assign a new value to per_user after initialization.") @property @@ -528,7 +528,7 @@ class ConversationHandler(BaseHandler[Update, CCT]): return self._per_chat @per_chat.setter - def per_chat(self, value: object) -> NoReturn: + def per_chat(self, _: object) -> NoReturn: raise AttributeError("You can not assign a new value to per_chat after initialization.") @property @@ -537,7 +537,7 @@ class ConversationHandler(BaseHandler[Update, CCT]): return self._per_message @per_message.setter - def per_message(self, value: object) -> NoReturn: + def per_message(self, _: object) -> NoReturn: raise AttributeError("You can not assign a new value to per_message after initialization.") @property @@ -551,7 +551,7 @@ class ConversationHandler(BaseHandler[Update, CCT]): return self._conversation_timeout @conversation_timeout.setter - def conversation_timeout(self, value: object) -> NoReturn: + def conversation_timeout(self, _: object) -> NoReturn: raise AttributeError( "You can not assign a new value to conversation_timeout after initialization." ) @@ -562,7 +562,7 @@ class ConversationHandler(BaseHandler[Update, CCT]): return self._name @name.setter - def name(self, value: object) -> NoReturn: + def name(self, _: object) -> NoReturn: raise AttributeError("You can not assign a new value to name after initialization.") @property @@ -574,7 +574,7 @@ class ConversationHandler(BaseHandler[Update, CCT]): return self._persistent @persistent.setter - def persistent(self, value: object) -> NoReturn: + def persistent(self, _: object) -> NoReturn: raise AttributeError("You can not assign a new value to persistent after initialization.") @property @@ -586,7 +586,7 @@ class ConversationHandler(BaseHandler[Update, CCT]): return self._map_to_parent @map_to_parent.setter - def map_to_parent(self, value: object) -> NoReturn: + def map_to_parent(self, _: object) -> NoReturn: raise AttributeError( "You can not assign a new value to map_to_parent after initialization." ) diff --git a/telegram/ext/_handlers/inlinequeryhandler.py b/telegram/ext/_handlers/inlinequeryhandler.py index 1db74fb28..21a5925cb 100644 --- a/telegram/ext/_handlers/inlinequeryhandler.py +++ b/telegram/ext/_handlers/inlinequeryhandler.py @@ -130,8 +130,8 @@ class InlineQueryHandler(BaseHandler[Update, CCT]): def collect_additional_context( self, context: CCT, - update: Update, - application: "Application[Any, CCT, Any, Any, Any, Any]", + update: Update, # noqa: ARG002 + application: "Application[Any, CCT, Any, Any, Any, Any]", # noqa: ARG002 check_result: Optional[Union[bool, Match[str]]], ) -> None: """Add the result of ``re.match(pattern, update.inline_query.query)`` to diff --git a/telegram/ext/_handlers/messagehandler.py b/telegram/ext/_handlers/messagehandler.py index fab4422fe..0cd42884b 100644 --- a/telegram/ext/_handlers/messagehandler.py +++ b/telegram/ext/_handlers/messagehandler.py @@ -102,8 +102,8 @@ class MessageHandler(BaseHandler[Update, CCT]): def collect_additional_context( self, context: CCT, - update: Update, - application: "Application[Any, CCT, Any, Any, Any, Any]", + update: Update, # noqa: ARG002 + application: "Application[Any, CCT, Any, Any, Any, Any]", # noqa: ARG002 check_result: Optional[Union[bool, Dict[str, object]]], ) -> None: """Adds possible output of data filters to the :class:`CallbackContext`.""" diff --git a/telegram/ext/_handlers/prefixhandler.py b/telegram/ext/_handlers/prefixhandler.py index 00a9ff196..3b10a0a1c 100644 --- a/telegram/ext/_handlers/prefixhandler.py +++ b/telegram/ext/_handlers/prefixhandler.py @@ -171,8 +171,8 @@ class PrefixHandler(BaseHandler[Update, CCT]): def collect_additional_context( self, context: CCT, - update: Update, - application: "Application[Any, CCT, Any, Any, Any, Any]", + update: Update, # noqa: ARG002 + application: "Application[Any, CCT, Any, Any, Any, Any]", # noqa: ARG002 check_result: Optional[Union[bool, Tuple[List[str], Optional[bool]]]], ) -> None: """Add text after the command to :attr:`CallbackContext.args` as list, split on single diff --git a/telegram/ext/_handlers/stringcommandhandler.py b/telegram/ext/_handlers/stringcommandhandler.py index 2fa085899..d9d25408c 100644 --- a/telegram/ext/_handlers/stringcommandhandler.py +++ b/telegram/ext/_handlers/stringcommandhandler.py @@ -98,8 +98,8 @@ class StringCommandHandler(BaseHandler[str, CCT]): def collect_additional_context( self, context: CCT, - update: str, - application: "Application[Any, CCT, Any, Any, Any, Any]", + update: str, # noqa: ARG002 + application: "Application[Any, CCT, Any, Any, Any, Any]", # noqa: ARG002 check_result: Optional[List[str]], ) -> None: """Add text after the command to :attr:`CallbackContext.args` as list, split on single diff --git a/telegram/ext/_handlers/stringregexhandler.py b/telegram/ext/_handlers/stringregexhandler.py index 2eeb2b4d0..68cc50612 100644 --- a/telegram/ext/_handlers/stringregexhandler.py +++ b/telegram/ext/_handlers/stringregexhandler.py @@ -103,8 +103,8 @@ class StringRegexHandler(BaseHandler[str, CCT]): def collect_additional_context( self, context: CCT, - update: str, - application: "Application[Any, CCT, Any, Any, Any, Any]", + update: str, # noqa: ARG002 + application: "Application[Any, CCT, Any, Any, Any, Any]", # noqa: ARG002 check_result: Optional[Match[str]], ) -> None: """Add the result of ``re.match(pattern, update)`` to :attr:`CallbackContext.matches` as diff --git a/telegram/ext/filters.py b/telegram/ext/filters.py index f2820d2b2..1d84ceebe 100644 --- a/telegram/ext/filters.py +++ b/telegram/ext/filters.py @@ -401,7 +401,7 @@ class _InvertedFilter(UpdateFilter): return f"" @name.setter - def name(self, name: str) -> NoReturn: + def name(self, _: str) -> NoReturn: raise RuntimeError("Cannot set name for combined filters.") @@ -492,7 +492,7 @@ class _MergedFilter(UpdateFilter): ) @name.setter - def name(self, name: str) -> NoReturn: + def name(self, _: str) -> NoReturn: raise RuntimeError("Cannot set name for combined filters.") @@ -522,14 +522,14 @@ class _XORFilter(UpdateFilter): return f"<{self.base_filter} xor {self.xor_filter}>" @name.setter - def name(self, name: str) -> NoReturn: + def name(self, _: str) -> NoReturn: raise RuntimeError("Cannot set name for combined filters.") class _All(MessageFilter): __slots__ = () - def filter(self, message: Message) -> bool: + def filter(self, message: Message) -> bool: # noqa: ARG002 return True @@ -809,7 +809,7 @@ class _ChatUserBaseFilter(MessageFilter, ABC): ) @name.setter - def name(self, name: str) -> NoReturn: + def name(self, _: str) -> NoReturn: raise RuntimeError(f"Cannot set name for filters.{self.__class__.__name__}")