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