Skip to content

Commit 1fef719

Browse files
committed
feat: ruff for lint
1 parent 25ec587 commit 1fef719

File tree

17 files changed

+89
-717
lines changed

17 files changed

+89
-717
lines changed

poetry.lock

Lines changed: 29 additions & 548 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pybotx/bot/bot.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@
235235
from pybotx.models.bot_catalog import BotsListItem
236236
from pybotx.models.chats import ChatInfo, ChatListItem
237237
from pybotx.models.commands import (
238-
BotAPICommand,
239238
BotAPISystemEvent,
240239
BotAPIIncomingMessage,
241240
BotCommand,
@@ -322,7 +321,9 @@ def async_execute_raw_bot_command(
322321
if command_type == BotAPICommandTypes.USER:
323322
bot_api_command = BotAPIIncomingMessage.model_validate(raw_bot_command)
324323
else:
325-
bot_api_command = TypeAdapter(BotAPISystemEvent).validate_python(raw_bot_command)
324+
bot_api_command = TypeAdapter(BotAPISystemEvent).validate_python(
325+
raw_bot_command
326+
)
326327
except ValidationError as validation_exc:
327328
raise ValueError("Bot command validation error") from validation_exc
328329

@@ -393,7 +394,9 @@ async def raw_get_status(
393394
self._verify_request(request_headers, trusted_issuers=trusted_issuers)
394395

395396
try:
396-
bot_api_status_recipient = BotAPIStatusRecipient.model_validate(query_params)
397+
bot_api_status_recipient = BotAPIStatusRecipient.model_validate(
398+
query_params
399+
)
397400
except ValidationError as exc:
398401
raise ValueError("Status request validation error") from exc
399402

@@ -551,7 +554,7 @@ async def answer_message(
551554
:return: Notification sync_id.
552555
"""
553556

554-
try: # noqa: WPS229
557+
try:
555558
bot_id = bot_id_var.get()
556559
chat_id = chat_id_var.get()
557560
except LookupError as exc:
@@ -2069,7 +2072,7 @@ async def collect_metric(
20692072
)
20702073
await method.execute(payload)
20712074

2072-
def _verify_request( # noqa: WPS231, WPS238
2075+
def _verify_request(
20732076
self,
20742077
headers: Optional[Mapping[str, str]],
20752078
*,

pybotx/bot/bot_accounts_storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def iter_bot_accounts(self) -> Iterator[BotAccountWithSecret]:
2525

2626
def get_cts_url(self, bot_id: UUID) -> str:
2727
bot_account = self.get_bot_account(bot_id)
28-
return bot_account.cts_url
28+
return str(bot_account.cts_url)
2929

3030
def set_token(self, bot_id: UUID, token: str) -> None:
3131
self._auth_tokens[bot_id] = token

pybotx/client/botx_method.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ async def _process_callback(
155155
callback_timeout: Optional[float],
156156
default_callback_timeout: float,
157157
) -> Optional[BotXMethodCallback]:
158-
assert (
159-
self._callbacks_manager is not None
160-
), "CallbackManager hasn't been passed to this method"
158+
assert self._callbacks_manager is not None, (
159+
"CallbackManager hasn't been passed to this method"
160+
)
161161

162162
await self._callbacks_manager.create_botx_method_callback(sync_id)
163163

pybotx/client/chats_api/chat_info.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ class BotXAPIChatInfoResult(VerifiedPayloadBaseModel):
4545

4646
@field_validator("members", mode="before")
4747
@classmethod
48-
def validate_members(cls, value: List[Union[BotXAPIChatInfoMember, Dict[str, Any]]]) -> List[Union[BotXAPIChatInfoMember, Dict[str, Any]]]:
48+
def validate_members(
49+
cls, value: List[Union[BotXAPIChatInfoMember, Dict[str, Any]]]
50+
) -> List[Union[BotXAPIChatInfoMember, Dict[str, Any]]]:
4951
parsed: List[Union[BotXAPIChatInfoMember, Dict[str, Any]]] = []
5052
for item in value:
5153
if isinstance(item, dict):
@@ -64,7 +66,9 @@ class BotXAPIChatInfoResponsePayload(VerifiedPayloadBaseModel):
6466

6567
def to_domain(self) -> ChatInfo:
6668
if any(isinstance(member, dict) for member in self.result.members):
67-
logger.warning("One or more unsupported user types skipped") # pragma: no cover
69+
logger.warning(
70+
"One or more unsupported user types skipped"
71+
) # pragma: no cover
6872

6973
members = [
7074
ChatInfoMember(

pybotx/client/chats_api/list_chats.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ class BotXAPIListChatResponsePayload(VerifiedPayloadBaseModel):
2727

2828
@field_validator("result", mode="before")
2929
@classmethod
30-
def validate_result(cls, value: List[Union[BotXAPIListChatResult, Dict[str, Any]]]) -> List[Union[BotXAPIListChatResult, Dict[str, Any]]]:
30+
def validate_result(
31+
cls, value: List[Union[BotXAPIListChatResult, Dict[str, Any]]]
32+
) -> List[Union[BotXAPIListChatResult, Dict[str, Any]]]:
3133
parsed: List[Union[BotXAPIListChatResult, Dict[str, Any]]] = []
3234
for item in value:
3335
if isinstance(item, dict):
@@ -56,7 +58,9 @@ def to_domain(self) -> List[ChatListItem]:
5658
]
5759

5860
if len(chats_list) != len(self.result):
59-
logger.warning("One or more unsupported chat types skipped") # pragma: no cover
61+
logger.warning(
62+
"One or more unsupported chat types skipped"
63+
) # pragma: no cover
6064

6165
return chats_list
6266

pybotx/client/events_api/message_status_event.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class BotXAPIMessageStatusResponsePayload(VerifiedPayloadBaseModel):
4242
result: BotXAPIMessageStatusResult
4343

4444
def to_domain(self) -> MessageStatus:
45-
4645
return MessageStatus(
4746
group_chat_id=self.result.group_chat_id,
4847
sent_to=self.result.sent_to,

pybotx/models/bot_account.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ class BotAccountWithSecret(BaseModel):
1818
cts_url: AnyHttpUrl
1919
secret_key: str
2020

21-
model_config = ConfigDict()
21+
model_config = ConfigDict(frozen=True)
2222

2323
def __setattr__(self, name: str, value: object) -> None: # pragma: no cover
24-
if not self.Config.allow_mutation and name in self.model_fields:
24+
if not getattr(self.model_config, "frozen", True) and name in self.model_fields:
2525
raise TypeError("BotAccountWithSecret is immutable") # pragma: no cover
2626
super().__setattr__(name, value) # pragma: no cover
2727

@@ -33,10 +33,3 @@ def host(self) -> str:
3333
raise ValueError("Could not parse host from cts_url.")
3434

3535
return hostname
36-
37-
38-
class _Config:
39-
allow_mutation = False
40-
41-
42-
BotAccountWithSecret.Config = _Config

pybotx/models/commands.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
from typing import Union
1+
from typing import List, Union
22

33
from pybotx.models.message.incoming_message import (
44
BotAPIIncomingMessage,
55
IncomingMessage,
66
)
7+
8+
__all__: List[str] = [
9+
"BotAPIIncomingMessage",
10+
"IncomingMessage",
11+
"BotAPISystemEvent",
12+
"BotAPICommand",
13+
"SystemEvent",
14+
"BotCommand",
15+
]
716
from pybotx.models.system_events.added_to_chat import (
817
AddedToChatEvent,
918
BotAPIAddedToChat,

pybotx/models/message/incoming_message.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ def convert_bot_api_entity_to_domain(api_entity: BotAPIEntity) -> Entity:
156156
return _convert_bot_api_mention_to_domain(api_entity.data)
157157

158158
if api_entity.type == BotAPIEntityTypes.FORWARD:
159-
160159
return Forward(
161160
chat_id=api_entity.data.group_chat_id,
162161
author_id=api_entity.data.sender_huid,
@@ -167,7 +166,6 @@ def convert_bot_api_entity_to_domain(api_entity: BotAPIEntity) -> Entity:
167166
)
168167

169168
if api_entity.type == BotAPIEntityTypes.REPLY:
170-
171169
mentions = MentionList()
172170
for api_mention_data in api_entity.data.mentions:
173171
mentions.append(_convert_bot_api_mention_to_domain(api_mention_data))
@@ -200,8 +198,12 @@ class BotAPIIncomingMessage(BotAPIBaseCommand):
200198

201199
@field_validator("attachments", "entities", mode="before")
202200
@classmethod
203-
def validate_items(cls, value, info): # pragma: no cover
204-
item_model = BotAPIAttachment if info.field_name == "attachments" else BotAPIEntity
201+
def validate_items(
202+
cls, value: List[Union[Dict[str, Any], Any]], info: Any
203+
) -> List[Any]: # pragma: no cover
204+
item_model = (
205+
BotAPIAttachment if info.field_name == "attachments" else BotAPIEntity
206+
)
205207
parsed = []
206208
for item in value:
207209
if isinstance(item, dict):

0 commit comments

Comments
 (0)