Skip to content

Commit

Permalink
fix: 修复部分类型错误 (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
st1020 authored Jul 20, 2024
1 parent 7b2a9b6 commit 35d85b0
Show file tree
Hide file tree
Showing 13 changed files with 379 additions and 376 deletions.
2 changes: 1 addition & 1 deletion .release.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def write_version_toml(file: Path, version: str, *, is_package: bool = False) ->
assert isinstance(dependencies_array, Array)
dependencies_array[0] = f"alicebot=={version}"
with file.open("w", encoding="utf-8") as f:
tomlkit.dump(toml_file, f)
tomlkit.dump(toml_file, f) # pyright: ignore[reportUnknownMemberType]


write_version_json(Path("package.json"), version)
Expand Down
5 changes: 4 additions & 1 deletion alicebot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,10 @@ async def get(
)
and (
adapter_type is None
or isinstance(self._current_event.adapter, adapter_type)
or isinstance(
self._current_event.adapter, # pyright: ignore[reportUnknownMemberType]
adapter_type,
)
)
and await _func(self._current_event)
):
Expand Down
6 changes: 4 additions & 2 deletions alicebot/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ async def solve_dependencies(
depend_obj.__init__() # type: ignore[misc] # pylint: disable=unnecessary-dunder-call

if isinstance(depend_obj, AbstractAsyncContextManager):
depend = await stack.enter_async_context(depend_obj)
depend = await stack.enter_async_context(
cast(AbstractAsyncContextManager[_T], depend_obj)
)
elif isinstance(depend_obj, AbstractContextManager):
depend = await stack.enter_async_context(
sync_ctx_manager_wrapper(depend_obj)
sync_ctx_manager_wrapper(cast(AbstractContextManager[_T], depend_obj))
)
else:
depend = depend_obj
Expand Down
2 changes: 1 addition & 1 deletion alicebot/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
BuildMessageType = Union[list[MessageSegmentT], MessageSegmentT, str, Mapping[str, Any]]


class Message(ABC, list[MessageSegmentT]):
class Message(ABC, list[MessageSegmentT], Generic[MessageSegmentT]):
"""消息。
本类是 `List` 的子类,并重写了 `__init__()` 方法,
Expand Down
5 changes: 4 additions & 1 deletion alicebot/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ def __init_subclass__(

if not hasattr(cls, "Config") and config is not None:
cls.Config = config
if cls.__init_state__ is Plugin.__init_state__ and init_state is not None:
if (
cls.__init_state__ is cast(Plugin[Any, Any, Any], Plugin).__init_state__ # type: ignore[comparison-overlap]
and init_state is not None
):
cls.__init_state__ = lambda _: init_state # type: ignore

@final
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@
"@iconify-json/mdi": "^1.1.67",
"unocss": "^0.58.9",
"vitepress": "^1.3.1",
"vue": "^3.4.31"
"vue": "^3.4.33"
},
"devDependencies": {
"@antfu/eslint-config": "^2.22.2",
"@types/node": "^20.14.10",
"@antfu/eslint-config": "^2.23.0",
"@types/node": "^20.14.11",
"@unocss/eslint-plugin": "^0.58.9",
"conventional-changelog-cli": "^4.1.0",
"eslint": "^8.57.0",
"markdownlint-cli2": "^0.8.1",
"prettier": "^3.3.3",
"pyright": "^1.1.371",
"pyright": "^1.1.372",
"zhlint": "^0.8.1"
},
"pnpm": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
APScheduler 使用方法请参考:[APScheduler](https://apscheduler.readthedocs.io/)。
"""

# pyright: reportUnknownMemberType=false, reportMissingTypeStubs = false
# ruff: noqa: B009, B010
import inspect
from collections.abc import Awaitable
Expand Down Expand Up @@ -138,7 +139,7 @@ async def _wrapper(self: PluginT) -> bool:

return _wrapper

cls.rule = _rule_decorator(cls.rule) # type: ignore
return cls # type: ignore
cls.rule = _rule_decorator(cls.rule) # type: ignore[method-assign]
return cls # type: ignore[return-value]

return _decorator
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
"""APScheduler 适配器事件。"""

# pyright: reportMissingTypeStubs = false
from typing import TYPE_CHECKING, Any, Optional, Type, Union # noqa: UP035

from apscheduler.job import Job
from apscheduler.triggers.base import BaseTrigger

from alicebot.event import Event
from alicebot.plugin import Plugin

if TYPE_CHECKING:
from alicebot.plugin import Plugin

from . import APSchedulerAdapter


Expand All @@ -19,7 +21,10 @@ class APSchedulerEvent(Event["APSchedulerAdapter"]):
"""APSchedulerEvent 事件基类。"""

type: Optional[str] = "apscheduler"
plugin_class: Type[Plugin] # type: ignore # noqa: UP006
if TYPE_CHECKING:
plugin_class: Type[Plugin[Any, Any, Any]] # noqa: UP006
else:
plugin_class: Any

@property
def job(self) -> Job:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from alicebot.event import Event

if TYPE_CHECKING:
from .. import MiraiAdapter
from .. import MiraiAdapter # noqa: TID252

Permission = Literal["OWNER", "ADMINISTRATOR", "MEMBER"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from alicebot.event import MessageEvent as BaseMessageEvent
from alicebot.message import BuildMessageType

from ..message import MiraiMessage, MiraiMessageSegment
from ..message import MiraiMessage, MiraiMessageSegment # noqa: TID252
from .base import FriendInfo, GroupMemberInfo, MiraiEvent, OtherClientSender

if TYPE_CHECKING:
from .. import MiraiAdapter
from .. import MiraiAdapter # noqa: TID252


class MiraiBaseMessageEvent(MiraiEvent, BaseMessageEvent["MiraiAdapter"]):
Expand Down
Loading

0 comments on commit 35d85b0

Please sign in to comment.