Feature: 支持 PEP 695 类型别名 (#3621)

This commit is contained in:
Ju4tCode
2025-08-07 14:54:22 +08:00
committed by GitHub
parent 56f52f2c9f
commit 0d8b81614a
16 changed files with 232 additions and 9 deletions

View File

@ -7,13 +7,14 @@ FrontMatter:
"""
import inspect
from typing import Any, Callable, ForwardRef
from typing import Any, Callable, ForwardRef, cast
from typing_extensions import TypeAliasType
from loguru import logger
from nonebot.compat import ModelField
from nonebot.exception import TypeMisMatch
from nonebot.typing import evaluate_forwardref
from nonebot.typing import evaluate_forwardref, is_type_alias_type
def get_typed_signature(call: Callable[..., Any]) -> inspect.Signature:
@ -46,6 +47,9 @@ def get_typed_annotation(param: inspect.Parameter, globalns: dict[str, Any]) ->
f'Unknown ForwardRef["{param.annotation}"] for parameter {param.name}'
)
return inspect.Parameter.empty
if is_type_alias_type(annotation):
# Python 3.12+ supports PEP 695 TypeAliasType
annotation = cast(TypeAliasType, annotation).__value__
return annotation