2020-06-30 10:13:58 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
2018-10-16 01:03:50 +08:00
|
|
|
|
2020-08-07 17:05:08 +08:00
|
|
|
from types import ModuleType
|
2020-08-10 13:06:02 +08:00
|
|
|
from typing import NoReturn, TYPE_CHECKING
|
2020-08-07 17:05:08 +08:00
|
|
|
from typing import Any, Set, List, Dict, Type, Tuple, Mapping
|
2020-08-10 13:06:02 +08:00
|
|
|
from typing import Union, TypeVar, Optional, Iterable, Callable, Awaitable
|
2020-08-07 17:05:08 +08:00
|
|
|
|
2020-08-07 17:51:57 +08:00
|
|
|
# import some modules needed when checking types
|
2020-08-07 17:05:08 +08:00
|
|
|
if TYPE_CHECKING:
|
2020-08-10 13:06:02 +08:00
|
|
|
from nonebot.matcher import Matcher as MatcherClass
|
|
|
|
from nonebot.drivers import BaseDriver, BaseWebSocket
|
2020-08-10 14:50:12 +08:00
|
|
|
from nonebot.adapters import BaseBot, BaseEvent, BaseMessage, BaseMessageSegment
|
2020-06-30 10:13:58 +08:00
|
|
|
|
2020-08-07 17:51:57 +08:00
|
|
|
|
2020-08-08 23:08:01 +08:00
|
|
|
def overrides(InterfaceClass: object):
|
2020-08-07 17:51:57 +08:00
|
|
|
|
2020-08-08 23:08:01 +08:00
|
|
|
def overrider(func: Callable) -> Callable:
|
2020-08-07 17:51:57 +08:00
|
|
|
assert func.__name__ in dir(
|
|
|
|
InterfaceClass), f"Error method: {func.__name__}"
|
|
|
|
return func
|
|
|
|
|
|
|
|
return overrider
|
|
|
|
|
|
|
|
|
2020-08-10 13:06:02 +08:00
|
|
|
Driver = TypeVar("Driver", bound="BaseDriver")
|
|
|
|
WebSocket = TypeVar("WebSocket", bound="BaseWebSocket")
|
|
|
|
|
|
|
|
Bot = TypeVar("Bot", bound="BaseBot")
|
2020-08-10 14:50:12 +08:00
|
|
|
Event = TypeVar("Event", bound="BaseEvent")
|
2020-08-10 13:06:02 +08:00
|
|
|
Message = TypeVar("Message", bound="BaseMessage")
|
|
|
|
MessageSegment = TypeVar("MessageSegment", bound="BaseMessageSegment")
|
|
|
|
|
|
|
|
PreProcessor = Callable[[Bot, Event], Union[Awaitable[None],
|
|
|
|
Awaitable[NoReturn]]]
|
|
|
|
|
|
|
|
Matcher = TypeVar("Matcher", bound="MatcherClass")
|
2020-08-13 15:23:04 +08:00
|
|
|
Handler = Callable[[Bot, Event, Dict[Any, Any]], Union[Awaitable[None],
|
|
|
|
Awaitable[NoReturn]]]
|