```
B = TypeVar("B", bound="Bot")
R = TypeVar("R")
P = ParamSpec("P")
class API(Generic[B, P, R]):
def __init__(self, func: Callable[Concatenate[B, P], Awaitable[R]]) -> None:
self.func = func
def __set_name__(self, owner: Type[B], name: str) -> None:
self.name = name
@overload
def __get__(self, obj: None, objtype: Type[B]) -> "API[B, P, R]": ...
@overload
def __get__(
self, obj: B, objtype: Optional[Type[B]]
) -> Callable[P, Awaitable[R]]: ...
def __get__(
self, obj: Optional[B], objtype: Optional[Type[B]] = None
) -> "API[B, P, R] | Callable[P, Awaitable[R]]":
if obj is None:
return self
return partial(obj.call_api, self.name) # type: ignore
async def __call__(self, inst: B, *args: P.args, **kwds: P.kwargs) -> R:
return await self.func(inst, *args, **kwds)
```
可以参考这个库的代码
https://github.com/nonebot/adapter-dodo/blob/83d55b09a9787c55d06fb01a5bb9c1f2d6a61fde/nonebot/adapters/dodo/utils.py#L39
像下面这个函数
https://github.com/nonebot/adapter-dodo/blob/83d55b09a9787c55d06fb01a5bb9c1f2d6a61fde/nonebot/adapters/dodo/bot.py#L298
被上面这个装饰器装饰过后就没有参数提示了...
在不换 IDE 的情况下该怎么做😭😭😭 |
|