Skip to content

Commit b84476f

Browse files
committed
refactor: improve logging format in command bot and enhance exception handling for unsupported types
1 parent 1589d3b commit b84476f

4 files changed

Lines changed: 24 additions & 7 deletions

File tree

examples/command_bot.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ async def on_message(client: TryxClient, event: EvMessage) -> None:
7070
return
7171

7272
print(
73-
f"[message] from={jid_to_text(sender_jid)} chat={jid_to_text(chat_jid)} text={text!r}"
73+
"[message] "
74+
f"from={jid_to_text(sender_jid)} "
75+
f"chat={jid_to_text(chat_jid)} "
76+
f"text={text!r}"
7477
)
7578

7679
if text in {"help", "menu"}:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ docs = [
7575
[tool.ruff]
7676
line-length = 88
7777
target-version = "py38"
78-
extend-exclude = ["target", "site", "libs", "python/tryx/waproto/whatsapp_pb2.pyi"]
78+
extend-exclude = ["target", "site", "libs", "python/tryx/waproto/whatsapp_pb2.py", "python/tryx/waproto/whatsapp_pb2.pyi"]
7979

8080
[tool.ruff.lint]
8181
select = ["E", "F", "W", "I", "UP", "B"]

python/tryx/client.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""High-level client API surface for Tryx Python bindings."""
22

3-
from typing import Any, Awaitable, Callable, Type, TypeVar
3+
from typing import Any, Awaitable, Callable, TypeVar
44

55
from .backend import BackendBase
66
from .events import EvMessage
@@ -55,7 +55,7 @@ class Tryx:
5555
def __init__(self, backend: BackendBase) -> None: ...
5656
def get_client(self) -> TryxClient: ...
5757
def on(
58-
self, event_type: Type[EventT]
58+
self, event_type: type[EventT]
5959
) -> Callable[[Callable[..., Awaitable[Any]]], Callable[..., Awaitable[Any]]]: ...
6060
def run(self) -> Awaitable[None]: ...
6161
def run_blocking(self) -> None: ...

python/tryx/exceptions.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,23 @@
55
if isinstance(obj, type):
66
globals()[name] = obj
77

8+
# Prefer modern names, but gracefully fall back to legacy names when needed.
9+
FailedBuildBot = globals().get("FailedBuildBot") or globals().get("BuildBotError")
10+
UnsupportedEventType = globals().get("UnsupportedEventType") or globals().get(
11+
"UnsupportedEventTypeError"
12+
)
13+
UnsupportedBackend = globals().get("UnsupportedBackend") or globals().get(
14+
"UnsupportedBackendError"
15+
)
16+
817
# Backward-compatible aliases for older Python API names.
9-
BuildBotError = FailedBuildBot
10-
UnsupportedEventTypeError = UnsupportedEventType
11-
UnsupportedBackendError = UnsupportedBackend
18+
if isinstance(FailedBuildBot, type):
19+
BuildBotError = FailedBuildBot
20+
21+
if isinstance(UnsupportedEventType, type):
22+
UnsupportedEventTypeError = UnsupportedEventType
23+
24+
if isinstance(UnsupportedBackend, type):
25+
UnsupportedBackendError = UnsupportedBackend
1226

1327
__all__ = sorted(name for name, obj in globals().items() if isinstance(obj, type))

0 commit comments

Comments
 (0)