Skip to content

Commit

Permalink
Add New Rules to ruff Config (#4250)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshil21 committed May 12, 2024
1 parent 5b0e0b5 commit f3bd0f1
Show file tree
Hide file tree
Showing 19 changed files with 59 additions and 54 deletions.
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion telegram/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8850,7 +8850,7 @@ async def replace_sticker_in_set(
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}

Expand Down
2 changes: 1 addition & 1 deletion telegram/_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def _de_json(
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):
Expand Down
5 changes: 4 additions & 1 deletion telegram/_passport/encryptedpassportelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ def __init__(
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,
):
Expand Down
2 changes: 1 addition & 1 deletion telegram/ext/_aioratelimiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ async def process_request(
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]]:
Expand Down
2 changes: 1 addition & 1 deletion telegram/ext/_basepersistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def update_interval(self) -> float:
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."
)
Expand Down
2 changes: 1 addition & 1 deletion telegram/ext/_baseupdateprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions telegram/ext/_callbackcontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def bot_data(self) -> 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}"
)
Expand All @@ -192,7 +192,7 @@ def chat_data(self) -> Optional[CD]:
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}"
)
Expand All @@ -214,7 +214,7 @@ def user_data(self) -> Optional[UD]:
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}"
)
Expand Down
20 changes: 10 additions & 10 deletions telegram/ext/_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def parse_mode(self) -> Optional[str]:
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
Expand All @@ -246,7 +246,7 @@ def explanation_parse_mode(self) -> Optional[str]:
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."
)
Expand All @@ -259,7 +259,7 @@ def quote_parse_mode(self) -> Optional[str]:
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."
)
Expand All @@ -272,7 +272,7 @@ def disable_notification(self) -> Optional[bool]:
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."
)
Expand All @@ -289,7 +289,7 @@ def disable_web_page_preview(self) -> ODVInput[bool]:
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."
)
Expand All @@ -302,7 +302,7 @@ def allow_sending_without_reply(self) -> Optional[bool]:
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."
)
Expand All @@ -318,7 +318,7 @@ def quote(self) -> Optional[bool]:
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
Expand All @@ -329,7 +329,7 @@ def tzinfo(self) -> datetime.tzinfo:
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
Expand All @@ -341,7 +341,7 @@ def block(self) -> bool:
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
Expand All @@ -354,7 +354,7 @@ def protect_content(self) -> Optional[bool]:
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."
)
Expand Down
4 changes: 2 additions & 2 deletions telegram/ext/_handlers/callbackqueryhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ def check_update(self, update: object) -> Optional[Union[bool, object]]:
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
Expand Down
4 changes: 2 additions & 2 deletions telegram/ext/_handlers/choseninlineresulthandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def check_update(self, update: object) -> Optional[Union[bool, object]]:
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
Expand Down
4 changes: 2 additions & 2 deletions telegram/ext/_handlers/commandhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ def check_update(
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
Expand Down
22 changes: 11 additions & 11 deletions telegram/ext/_handlers/conversationhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def entry_points(self) -> List[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."
)
Expand All @@ -487,7 +487,7 @@ def states(self) -> Dict[object, List[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
Expand All @@ -499,7 +499,7 @@ def fallbacks(self) -> List[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
Expand All @@ -508,7 +508,7 @@ def allow_reentry(self) -> bool:
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."
)
Expand All @@ -519,7 +519,7 @@ def per_user(self) -> bool:
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
Expand All @@ -528,7 +528,7 @@ def per_chat(self) -> bool:
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
Expand All @@ -537,7 +537,7 @@ def per_message(self) -> bool:
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
Expand All @@ -551,7 +551,7 @@ def conversation_timeout(
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."
)
Expand All @@ -562,7 +562,7 @@ def name(self) -> Optional[str]:
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
Expand All @@ -574,7 +574,7 @@ def persistent(self) -> bool:
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
Expand All @@ -586,7 +586,7 @@ def map_to_parent(self) -> Optional[Dict[object, object]]:
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."
)
Expand Down
4 changes: 2 additions & 2 deletions telegram/ext/_handlers/inlinequeryhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def check_update(self, update: object) -> Optional[Union[bool, Match[str]]]:
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
Expand Down
4 changes: 2 additions & 2 deletions telegram/ext/_handlers/messagehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def check_update(self, update: object) -> Optional[Union[bool, Dict[str, List[An
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`."""
Expand Down
4 changes: 2 additions & 2 deletions telegram/ext/_handlers/prefixhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ def check_update(
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
Expand Down
4 changes: 2 additions & 2 deletions telegram/ext/_handlers/stringcommandhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def check_update(self, update: object) -> Optional[List[str]]:
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
Expand Down
4 changes: 2 additions & 2 deletions telegram/ext/_handlers/stringregexhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def check_update(self, update: object) -> Optional[Match[str]]:
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
Expand Down

0 comments on commit f3bd0f1

Please sign in to comment.