mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-28 02:55:18 +08:00
💡 add di docstrings
This commit is contained in:
parent
aef585c60c
commit
f9674da6ea
@ -1,8 +1,4 @@
|
|||||||
"""
|
"""本模块模块实现了依赖注入的定义与处理。"""
|
||||||
## 依赖注入处理模块
|
|
||||||
|
|
||||||
该模块实现了依赖注入的定义与处理。
|
|
||||||
"""
|
|
||||||
|
|
||||||
import abc
|
import abc
|
||||||
import inspect
|
import inspect
|
||||||
@ -23,6 +19,11 @@ R = TypeVar("R")
|
|||||||
|
|
||||||
|
|
||||||
class Param(abc.ABC, FieldInfo):
|
class Param(abc.ABC, FieldInfo):
|
||||||
|
"""依赖注入的基本单元 —— 参数。
|
||||||
|
|
||||||
|
继承自 `pydantic.fields.FieldInfo`,用于描述参数信息(不包括参数名)。
|
||||||
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _check_param(
|
def _check_param(
|
||||||
cls, dependent: "Dependent", name: str, param: inspect.Parameter
|
cls, dependent: "Dependent", name: str, param: inspect.Parameter
|
||||||
@ -45,6 +46,16 @@ class CustomConfig(BaseConfig):
|
|||||||
|
|
||||||
|
|
||||||
class Dependent(Generic[R]):
|
class Dependent(Generic[R]):
|
||||||
|
"""依赖注入容器
|
||||||
|
|
||||||
|
参数:
|
||||||
|
call: 依赖注入的可调用对象,可以是任何 Callable 对象
|
||||||
|
pre_checkers: 依赖注入解析前的参数检查
|
||||||
|
params: 具名参数列表
|
||||||
|
parameterless: 匿名参数列表
|
||||||
|
allow_types: 允许的参数类型
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
@ -192,3 +203,6 @@ class Dependent(Generic[R]):
|
|||||||
values[field.name] = value
|
values[field.name] = value
|
||||||
|
|
||||||
return values
|
return values
|
||||||
|
|
||||||
|
|
||||||
|
__autodoc__ = {"CustomConfig": False}
|
||||||
|
@ -6,6 +6,7 @@ from pydantic.typing import ForwardRef, evaluate_forwardref
|
|||||||
|
|
||||||
|
|
||||||
def get_typed_signature(call: Callable[..., Any]) -> inspect.Signature:
|
def get_typed_signature(call: Callable[..., Any]) -> inspect.Signature:
|
||||||
|
"""获取可调用对象签名"""
|
||||||
signature = inspect.signature(call)
|
signature = inspect.signature(call)
|
||||||
globalns = getattr(call, "__globals__", {})
|
globalns = getattr(call, "__globals__", {})
|
||||||
typed_params = [
|
typed_params = [
|
||||||
@ -22,6 +23,7 @@ def get_typed_signature(call: Callable[..., Any]) -> inspect.Signature:
|
|||||||
|
|
||||||
|
|
||||||
def get_typed_annotation(param: inspect.Parameter, globalns: Dict[str, Any]) -> Any:
|
def get_typed_annotation(param: inspect.Parameter, globalns: Dict[str, Any]) -> Any:
|
||||||
|
"""获取参数的类型注解"""
|
||||||
annotation = param.annotation
|
annotation = param.annotation
|
||||||
if isinstance(annotation, str):
|
if isinstance(annotation, str):
|
||||||
annotation = ForwardRef(annotation)
|
annotation = ForwardRef(annotation)
|
||||||
|
Loading…
Reference in New Issue
Block a user