mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-24 09:05:04 +08:00
46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from types import ModuleType
|
|
from typing import NoReturn, TYPE_CHECKING
|
|
from typing import Any, Set, List, Dict, Type, Tuple, Mapping
|
|
from typing import Union, TypeVar, Optional, Iterable, Callable, Awaitable
|
|
|
|
# import some modules needed when checking types
|
|
if TYPE_CHECKING:
|
|
from nonebot.rule import BaseRule
|
|
from nonebot.matcher import Matcher as MatcherClass
|
|
from nonebot.drivers import BaseDriver, BaseWebSocket
|
|
from nonebot.adapters import BaseBot, BaseEvent, BaseMessage, BaseMessageSegment
|
|
|
|
|
|
def overrides(InterfaceClass: object):
|
|
|
|
def overrider(func: Callable) -> Callable:
|
|
assert func.__name__ in dir(
|
|
InterfaceClass), f"Error method: {func.__name__}"
|
|
return func
|
|
|
|
return overrider
|
|
|
|
|
|
Driver = TypeVar("Driver", bound="BaseDriver")
|
|
WebSocket = TypeVar("WebSocket", bound="BaseWebSocket")
|
|
|
|
Bot = TypeVar("Bot", bound="BaseBot")
|
|
Event = TypeVar("Event", bound="BaseEvent")
|
|
Message = TypeVar("Message", bound="BaseMessage")
|
|
MessageSegment = TypeVar("MessageSegment", bound="BaseMessageSegment")
|
|
|
|
PreProcessor = Callable[[Bot, Event], Union[Awaitable[None],
|
|
Awaitable[NoReturn]]]
|
|
|
|
Matcher = TypeVar("Matcher", bound="MatcherClass")
|
|
Handler = Callable[[Bot, Event, Dict[Any, Any]], Union[Awaitable[None],
|
|
Awaitable[NoReturn]]]
|
|
Rule = TypeVar("Rule", bound="BaseRule")
|
|
_RuleChecker_Return = TypeVar("_RuleChecker_Return", bool, Awaitable[bool])
|
|
RuleChecker = Callable[[Bot, Event], _RuleChecker_Return]
|
|
SyncRuleChecker = RuleChecker[Bot, Event, bool]
|
|
AsyncRuleChecker = RuleChecker[Bot, Event, Awaitable[bool]]
|