Skip to content

Commit d288c3e

Browse files
committed
some fix
1 parent b865d29 commit d288c3e

12 files changed

Lines changed: 40 additions & 45 deletions

File tree

pybotx/bot/callbacks/callback_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ def setup_callback_timeout_alarm(self, sync_id: UUID, timeout: float) -> None:
6969
def cancel_callback_timeout_alarm(
7070
self,
7171
sync_id: UUID,
72-
) -> None: ... # noqa: WPS428, E704
72+
) -> None: ...
7373

7474
@overload
7575
def cancel_callback_timeout_alarm(
7676
self,
7777
sync_id: UUID,
7878
return_remaining_time: Literal[True],
79-
) -> float: ... # noqa: WPS428, E704
79+
) -> float: ...
8080

8181
def cancel_callback_timeout_alarm(
8282
self,

pybotx/bot/callbacks/callback_memory_repo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pybotx.models.method_callbacks import BotXMethodCallback
99

1010
if TYPE_CHECKING:
11-
from asyncio import Future # noqa: WPS458
11+
from asyncio import Future
1212

1313

1414
class CallbackMemoryRepo(CallbackRepoProto):
@@ -37,7 +37,7 @@ async def wait_botx_method_callback(
3737
try:
3838
return await asyncio.wait_for(future, timeout=timeout)
3939
except asyncio.TimeoutError as exc:
40-
del self._callback_futures[sync_id] # noqa: WPS420
40+
del self._callback_futures[sync_id]
4141
raise CallbackNotReceivedError(sync_id) from exc
4242

4343
async def pop_botx_method_callback(

pybotx/bot/callbacks/callback_repo_proto.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,34 @@
44
from pybotx.models.method_callbacks import BotXMethodCallback
55

66
if TYPE_CHECKING:
7-
from asyncio import Future # noqa: WPS458
7+
from asyncio import Future
88

99
try:
1010
from typing import Protocol
1111
except ImportError:
12-
from typing_extensions import Protocol # type: ignore # noqa: WPS440
12+
from typing_extensions import Protocol # type: ignore
1313

1414

1515
class CallbackRepoProto(Protocol):
1616
async def create_botx_method_callback(
1717
self,
1818
sync_id: UUID,
19-
) -> None: ... # noqa: WPS428, E704
19+
) -> None: ...
2020

2121
async def set_botx_method_callback_result(
2222
self,
2323
callback: BotXMethodCallback,
24-
) -> None: ... # noqa: WPS428, E704
24+
) -> None: ...
2525

2626
async def wait_botx_method_callback(
2727
self,
2828
sync_id: UUID,
2929
timeout: float,
30-
) -> BotXMethodCallback: ... # noqa: WPS428, E704
30+
) -> BotXMethodCallback: ...
3131

3232
async def pop_botx_method_callback(
3333
self,
3434
sync_id: UUID,
35-
) -> "Future[BotXMethodCallback]": ... # noqa: WPS428, E704
35+
) -> "Future[BotXMethodCallback]": ...
3636

37-
async def stop_callbacks_waiting(self) -> None: ... # noqa: WPS428, E704
37+
async def stop_callbacks_waiting(self) -> None: ...

pybotx/bot/handler_collector.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,16 @@ def decorator(
199199
def default_message_handler(
200200
self,
201201
handler_func: IncomingMessageHandlerFunc,
202-
) -> IncomingMessageHandlerFunc: ... # noqa: WPS428, E704
202+
) -> IncomingMessageHandlerFunc: ...
203203

204204
@overload
205205
def default_message_handler(
206206
self,
207207
*,
208208
middlewares: Optional[Sequence[Middleware]] = None,
209-
) -> MessageHandlerDecorator: ... # noqa: WPS428, E704
209+
) -> MessageHandlerDecorator: ...
210210

211-
def default_message_handler( # noqa: WPS320
211+
def default_message_handler(
212212
self,
213213
handler_func: Optional[IncomingMessageHandlerFunc] = None,
214214
*,
@@ -222,7 +222,7 @@ def default_message_handler( # noqa: WPS320
222222
raise ValueError("Default command handler already registered")
223223

224224
def decorator(
225-
handler_func: IncomingMessageHandlerFunc, # noqa: WPS442
225+
handler_func: IncomingMessageHandlerFunc,
226226
) -> IncomingMessageHandlerFunc:
227227
self._default_message_handler = DefaultMessageHandler(
228228
handler_func=handler_func,
@@ -370,7 +370,7 @@ async def wait_active_tasks(self) -> None:
370370
return_when=asyncio.ALL_COMPLETED,
371371
)
372372

373-
def _include_collector(self, other: "HandlerCollector") -> None: # noqa: WPS238
373+
def _include_collector(self, other: "HandlerCollector") -> None:
374374
# - Message handlers -
375375
command_duplicates = set(self._user_commands_handlers) & set(
376376
other._user_commands_handlers,

pybotx/client/chats_api/create_chat.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
from typing import Any, Dict, List, Literal, Optional, Set, Union
1+
from typing import Any, Dict, List, Literal, Optional, Union
22
from uuid import UUID
33

44
from pydantic import (
55
Field,
66
ConfigDict,
7-
field_serializer,
87
field_validator,
98
model_validator,
109
)
@@ -33,7 +32,7 @@ class BotXAPICreateChatRequestPayload(UnverifiedPayloadBaseModel):
3332
description: Optional[str] = None
3433
chat_type: Union[APIChatTypes, ChatTypes]
3534
members: List[UUID]
36-
shared_history: Missing[bool]
35+
shared_history: Missing[bool] = Undefined
3736
avatar: Optional[str] = None
3837

3938
@model_validator(mode="before")
@@ -55,10 +54,6 @@ def _validate_avatar(cls, v: Optional[str]) -> Optional[str]:
5554
raise ValueError(f"Invalid data URL format: {e}")
5655
return v
5756

58-
@field_serializer("chat_type")
59-
def _serialize_chat_type(self, v: APIChatTypes) -> str:
60-
return v.value.lower()
61-
6257

6358
class BotXAPIChatIdResult(VerifiedPayloadBaseModel):
6459
model_config = ConfigDict(frozen=True)
@@ -90,11 +85,7 @@ async def execute(
9085
"""
9186
url = self._build_url("/api/v3/botx/chats/create")
9287

93-
exclude: Set[str] = (
94-
{"shared_history"} if payload.shared_history is Undefined else set()
95-
)
96-
97-
body = payload.model_dump(mode="json", exclude=exclude)
88+
body = payload.jsonable_dict()
9889

9990
response = await self._botx_method_call(
10091
"POST",

pybotx/client/events_api/edit_event.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class BotXAPIEditEventOpts(UnverifiedPayloadBaseModel):
3232
class BotXAPIEditEvent(UnverifiedPayloadBaseModel):
3333
body: Missing[str]
3434
metadata: Missing[Dict[str, Any]]
35-
opts: Missing[BotXAPIEditEventOpts]
35+
opts: Missing[BotXAPIEditEventPayloadOpts]
3636
bubble: Missing[BotXAPIMarkup]
3737
keyboard: Missing[BotXAPIMarkup]
3838
mentions: Missing[List[BotXAPIMention]]
@@ -41,7 +41,7 @@ class BotXAPIEditEvent(UnverifiedPayloadBaseModel):
4141
class BotXAPIEditEventRequestPayload(UnverifiedPayloadBaseModel):
4242
sync_id: UUID
4343
payload: BotXAPIEditEvent
44-
file: Missing[BotXAPIAttachment]
44+
file: MissingOptional[BotXAPIAttachment]
4545
opts: BotXAPIEditEventOpts
4646

4747
@classmethod

pybotx/client/smartapps_api/smartapp_manifest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,14 @@ async def execute(
8686
) -> BotXAPISmartAppManifestResponsePayload:
8787
path = "/api/v1/botx/smartapps/manifest"
8888

89+
body = payload.jsonable_dict()
90+
if not body or "manifest" not in body:
91+
body = {"manifest": {}}
92+
8993
response = await self._botx_method_call(
9094
"POST",
9195
self._build_url(path),
92-
json=payload.jsonable_dict(),
96+
json=body,
9397
)
9498

9599
return self._verify_and_extract_api_model(

pybotx/client/stickers_api/get_sticker_packs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
from uuid import UUID
33

44
from pybotx.client.authorized_botx_method import AuthorizedBotXMethod
5-
from pybotx.missing import Undefined
5+
from pybotx.missing import MissingOptional, Undefined
66
from pybotx.models.api_base import UnverifiedPayloadBaseModel, VerifiedPayloadBaseModel
77
from pybotx.models.stickers import StickerPackFromList, StickerPackPage
88

99

1010
class BotXAPIGetStickerPacksRequestPayload(UnverifiedPayloadBaseModel):
1111
user_huid: UUID
1212
limit: int
13-
after: Optional[str]
13+
after: MissingOptional[str]
1414

1515
@classmethod
1616
def from_domain(

pybotx/client/users_api/update_user_profile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class BotXAPIUpdateUserProfileRequestPayload(UnverifiedPayloadBaseModel):
1717
user_huid: UUID
1818
name: Missing[str] = Undefined
1919
public_name: Missing[str] = Undefined
20-
avatar: Missing[BotXAPIAttachment] = Undefined
20+
avatar: Missing[str] = Undefined
2121
company: Missing[str] = Undefined
2222
company_position: Missing[str] = Undefined
2323
description: Missing[str] = Undefined

pybotx/models/api_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __init__(
6666
_fields_set: Optional[Set[str]] = None,
6767
**kwargs: Any,
6868
) -> None:
69-
model = self.__class__.model_construct(_fields_set=_fields_set, **kwargs)
69+
model = self.__class__.model_validate(kwargs)
7070
self.__dict__.update(model.__dict__)
7171

7272
model_config = ConfigDict(arbitrary_types_allowed=True)

0 commit comments

Comments
 (0)