MCPcopy
hub / github.com/nonebot/nonebot2 / Depends

Function Depends

nonebot/internal/params.py:66–97  ·  view source on GitHub ↗

子依赖装饰器 参数: dependency: 依赖函数。默认为参数的类型注释。 use_cache: 是否使用缓存。默认为 `True`。 validate: 是否使用 Pydantic 类型校验。默认为 `False`。 用法: ```python def depend_func() -> Any: return ... def depend_gen_func(): try: yield ...

(
    dependency: T_Handler | None = None,
    *,
    use_cache: bool = True,
    validate: bool | PydanticFieldInfo = False,
)

Source from the content-addressed store, hash-verified

64
65
66def Depends(
67 dependency: T_Handler | None = None,
68 *,
69 use_cache: bool = True,
70 validate: bool | PydanticFieldInfo = False,
71) -> Any:
72 """子依赖装饰器
73
74 参数:
75 dependency: 依赖函数。默认为参数的类型注释。
76 use_cache: 是否使用缓存。默认为 `True`。
77 validate: 是否使用 Pydantic 类型校验。默认为 `False`。
78
79 用法:
80 ```python
81 def depend_func() -> Any:
82 return ...
83
84 def depend_gen_func():
85 try:
86 yield ...
87 finally:
88 ...
89
90 async def handler(
91 param_name: Any = Depends(depend_func),
92 gen: Any = Depends(depend_gen_func),
93 ):
94 ...
95 ```
96 """
97 return DependsInner(dependency, use_cache=use_cache, validate=validate)
98
99
100class CacheState(str, Enum):

Callers 15

EventTypeFunction · 0.90
EventMessageFunction · 0.90
EventPlainTextFunction · 0.90
EventToMeFunction · 0.90
CommandFunction · 0.90
RawCommandFunction · 0.90
CommandArgFunction · 0.90
CommandStartFunction · 0.90
CommandWhitespaceFunction · 0.90
ShellCommandArgsFunction · 0.90
ShellCommandArgvFunction · 0.90
RegexMatchedFunction · 0.90

Calls 1

DependsInnerClass · 0.85

Tested by 4

test_preprocessorFunction · 0.72
test_postprocessorFunction · 0.72
conn_hookFunction · 0.72
disconn_hookFunction · 0.72