mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-02-22 02:25:56 +08:00
fix docstring missing for nlp and event handler
This commit is contained in:
parent
a67fa5107c
commit
9fbd09331c
@ -1,5 +1,6 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import warnings
|
import warnings
|
||||||
|
from functools import update_wrapper
|
||||||
from typing import Set, Iterable, Optional, Callable, Union, NamedTuple
|
from typing import Set, Iterable, Optional, Callable, Union, NamedTuple
|
||||||
|
|
||||||
from aiocqhttp import Event as CQEvent
|
from aiocqhttp import Event as CQEvent
|
||||||
@ -14,7 +15,8 @@ from .typing import CommandName_T, CommandArgs_T
|
|||||||
|
|
||||||
class NLProcessor:
|
class NLProcessor:
|
||||||
__slots__ = ('func', 'keywords', 'permission', 'only_to_me',
|
__slots__ = ('func', 'keywords', 'permission', 'only_to_me',
|
||||||
'only_short_message', 'allow_empty_message')
|
'only_short_message', 'allow_empty_message', '__name__', '__qualname__', '__doc__',
|
||||||
|
'__annotations__', '__dict__')
|
||||||
|
|
||||||
def __init__(self, *, func: Callable, keywords: Optional[Iterable],
|
def __init__(self, *, func: Callable, keywords: Optional[Iterable],
|
||||||
permission: int, only_to_me: bool, only_short_message: bool,
|
permission: int, only_to_me: bool, only_short_message: bool,
|
||||||
@ -125,6 +127,7 @@ def on_natural_language(
|
|||||||
only_short_message=only_short_message,
|
only_short_message=only_short_message,
|
||||||
allow_empty_message=allow_empty_message)
|
allow_empty_message=allow_empty_message)
|
||||||
NLPManager.add_nl_processor(nl_processor)
|
NLPManager.add_nl_processor(nl_processor)
|
||||||
|
update_wrapper(wrapper=nl_processor, wrapped=func) # type: ignore
|
||||||
return nl_processor
|
return nl_processor
|
||||||
|
|
||||||
if isinstance(keywords, Callable):
|
if isinstance(keywords, Callable):
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from functools import update_wrapper
|
||||||
from typing import List, Optional, Callable, Union
|
from typing import List, Optional, Callable, Union
|
||||||
|
|
||||||
from aiocqhttp import Event as CQEvent
|
from aiocqhttp import Event as CQEvent
|
||||||
@ -11,7 +12,8 @@ from .session import BaseSession
|
|||||||
_bus = EventBus()
|
_bus = EventBus()
|
||||||
|
|
||||||
class EventHandler:
|
class EventHandler:
|
||||||
__slots__ = ('events', 'func')
|
__slots__ = ('events', 'func', '__name__', '__qualname__', '__doc__',
|
||||||
|
'__annotations__', '__dict__')
|
||||||
|
|
||||||
def __init__(self, events: List[str], func: Callable):
|
def __init__(self, events: List[str], func: Callable):
|
||||||
self.events = events
|
self.events = events
|
||||||
@ -26,10 +28,12 @@ def _make_event_deco(post_type: str) -> Callable:
|
|||||||
events_tmp = list(map(lambda x: f"{post_type}.{x}", [arg] + list(events)))
|
events_tmp = list(map(lambda x: f"{post_type}.{x}", [arg] + list(events)))
|
||||||
for e in events_tmp:
|
for e in events_tmp:
|
||||||
_bus.subscribe(e, func)
|
_bus.subscribe(e, func)
|
||||||
return EventHandler(events_tmp, func)
|
handler = EventHandler(events_tmp, func)
|
||||||
|
return update_wrapper(handler, func) # type: ignore
|
||||||
else:
|
else:
|
||||||
_bus.subscribe(post_type, func)
|
_bus.subscribe(post_type, func)
|
||||||
return EventHandler([post_type], func)
|
handler = EventHandler([post_type], func)
|
||||||
|
return update_wrapper(handler, func) # type: ignore
|
||||||
|
|
||||||
if isinstance(arg, Callable):
|
if isinstance(arg, Callable):
|
||||||
return deco(arg) # type: ignore
|
return deco(arg) # type: ignore
|
||||||
|
Loading…
x
Reference in New Issue
Block a user