🚨 Develop: 添加 ruff linter (#2114)

This commit is contained in:
Ju4tCode
2023-06-24 14:47:35 +08:00
committed by GitHub
parent fe21cbfa1d
commit 3d5dd5969c
53 changed files with 813 additions and 758 deletions

View File

@ -3,6 +3,7 @@ FrontMatter:
sidebar_position: 1
description: nonebot.dependencies.utils 模块
"""
import inspect
from typing import Any, Dict, TypeVar, Callable, ForwardRef
@ -17,6 +18,7 @@ V = TypeVar("V")
def get_typed_signature(call: Callable[..., Any]) -> inspect.Signature:
"""获取可调用对象签名"""
signature = inspect.signature(call)
globalns = getattr(call, "__globals__", {})
typed_params = [
@ -33,6 +35,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)
@ -47,6 +50,8 @@ def get_typed_annotation(param: inspect.Parameter, globalns: Dict[str, Any]) ->
def check_field_type(field: ModelField, value: V) -> V:
"""检查字段类型是否匹配"""
_, errs_ = field.validate(value, {}, loc=())
if errs_:
raise TypeMisMatch(field, value)