nonebot2/website/versioned_docs/version-2.0.0rc2/api/dependencies/index.md
github-actions[bot] d83866f03b 🔖 Release 2.0.0rc2
2022-11-24 03:55:37 +00:00

2.0 KiB

sidebar_position description
0 nonebot.dependencies 模块

nonebot.dependencies

本模块模块实现了依赖注入的定义与处理。

abstract class Param(default=PydanticUndefined, **kwargs)

  • 说明

    依赖注入的基本单元 —— 参数。

    继承自 pydantic.fields.FieldInfo,用于描述参数信息(不包括参数名)。

  • 参数

    • default (Any)

    • **kwargs (Any)

class Dependent(call, params=<factory>, parameterless=<factory>)

  • 说明

    依赖注入容器

  • 参数

    • call ((*Any, **Any) -> (~ R) | (*Any, **Any) -> Awaitable[(~ R)]): 依赖注入的可调用对象,可以是任何 Callable 对象

    • params (tuple[pydantic.fields.ModelField]): 具名参数列表

    • parameterless (tuple[Param]): 匿名参数列表

    • pre_checkers: 依赖注入解析前的参数检查

    • allow_types: 允许的参数类型

async method check(self, **params)

  • 参数

    • **params (Any)
  • 返回

    • None

classmethod parse(cls, *, call, parameterless=None, allow_types)

  • 参数

    • call ((*Any, **Any) -> (~ R) | (*Any, **Any) -> Awaitable[(~ R)])

    • parameterless (Iterable[Any] | None)

    • allow_types (Iterable[Type[Param]])

  • 返回

    • Dependent[R]

staticmethod parse_parameterless(parameterless, allow_types)

  • 参数

    • parameterless (tuple[Any, ...])

    • allow_types (tuple[Type[Param], ...])

  • 返回

staticmethod parse_params(call, allow_types)

  • 参数

    • call ((*Any, **Any) -> (~ R) | (*Any, **Any) -> Awaitable[(~ R)])

    • allow_types (tuple[Type[Param], ...])

  • 返回

    • tuple[pydantic.fields.ModelField]

async method solve(self, **params)

  • 参数

    • **params (Any)
  • 返回

    • dict[str, Any]