From dddee548aae625edb455de0c9689e200d8b7cdef Mon Sep 17 00:00:00 2001 From: st1020 Date: Wed, 22 Jan 2025 20:42:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(bot):=20=E4=B8=BA=20TypeVar=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=BB=98=E8=AE=A4=E5=80=BC=EF=BC=8C=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=20Plugin=20=E4=B8=8D=E6=8C=87=E5=AE=9A=E8=8C=83=E5=9E=8B?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=97=B6=E5=B0=86=E6=8F=90=E4=BE=9B=E5=90=88?= =?UTF-8?q?=E7=90=86=E7=9A=84=E9=BB=98=E8=AE=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alicebot/adapter/__init__.py | 4 ++-- alicebot/bot.py | 2 +- alicebot/typing.py | 9 +++++---- pyproject.toml | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/alicebot/adapter/__init__.py b/alicebot/adapter/__init__.py index a9212c0..3094502 100644 --- a/alicebot/adapter/__init__.py +++ b/alicebot/adapter/__init__.py @@ -12,11 +12,11 @@ Callable, Generic, Optional, - TypeVar, Union, final, overload, ) +from typing_extensions import TypeVar import structlog @@ -36,7 +36,7 @@ __import__("pkg_resources").declare_namespace(__name__) -_EventT = TypeVar("_EventT", bound="Event[Any]") +_EventT = TypeVar("_EventT", bound="Event[Any]", default="Event[Any]") class Adapter(Generic[EventT, ConfigT], ABC): diff --git a/alicebot/bot.py b/alicebot/bot.py index 4552b24..e47c659 100644 --- a/alicebot/bot.py +++ b/alicebot/bot.py @@ -601,7 +601,7 @@ async def get( func: Optional[Callable[[EventT], Union[bool, Awaitable[bool]]]] = None, *, event_type: type[EventT], - adapter_type: Optional[type[AdapterT]] = None, + adapter_type: Optional[type[Adapter[Any, Any]]] = None, max_try_times: Optional[int] = None, timeout: Optional[Union[int, float]] = None, ) -> EventT: ... diff --git a/alicebot/typing.py b/alicebot/typing.py index 0a7f1cd..4613223 100644 --- a/alicebot/typing.py +++ b/alicebot/typing.py @@ -6,7 +6,8 @@ # ruff: noqa: A005 from collections.abc import Awaitable -from typing import TYPE_CHECKING, Callable, Optional, TypeVar +from typing import TYPE_CHECKING, Callable, Optional +from typing_extensions import TypeVar from alicebot.message import BuildMessageType, MessageSegmentT, MessageT @@ -33,11 +34,11 @@ "StateT", ] -StateT = TypeVar("StateT") -EventT = TypeVar("EventT", bound="Event[Any]") +EventT = TypeVar("EventT", bound="Event[Any]", default="Event[Any]") +StateT = TypeVar("StateT", default=None) +ConfigT = TypeVar("ConfigT", bound=Optional["ConfigModel"], default=None) PluginT = TypeVar("PluginT", bound="Plugin[Any, Any, Any]") AdapterT = TypeVar("AdapterT", bound="Adapter[Any, Any]") -ConfigT = TypeVar("ConfigT", bound=Optional["ConfigModel"]) BotHook = Callable[["Bot"], Awaitable[None]] AdapterHook = Callable[["Adapter[Any, Any]"], Awaitable[None]] diff --git a/pyproject.toml b/pyproject.toml index 3867f44..66dcac3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ dependencies = [ "aiohttp>=3.8.0,<4.0.0", "structlog>=25.1.0,<26.0.0", "rich>=13.7.0,<14.0.0", - "typing-extensions>=4.5.0", + "typing-extensions>=4.12.0,<5.0.0", "anyio>=4.4.0,<5.0.0", ]