mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-27 18:45:05 +08:00
📝 Feature: 补充依赖注入部分情况下类型错误时的日志提示 (#2343)
This commit is contained in:
parent
805778794c
commit
81cb356503
@ -101,17 +101,21 @@ class Dependent(Generic[R]):
|
|||||||
)
|
)
|
||||||
|
|
||||||
async def __call__(self, **kwargs: Any) -> R:
|
async def __call__(self, **kwargs: Any) -> R:
|
||||||
# do pre-check
|
try:
|
||||||
await self.check(**kwargs)
|
# do pre-check
|
||||||
|
await self.check(**kwargs)
|
||||||
|
|
||||||
# solve param values
|
# solve param values
|
||||||
values = await self.solve(**kwargs)
|
values = await self.solve(**kwargs)
|
||||||
|
|
||||||
# call function
|
# call function
|
||||||
if is_coroutine_callable(self.call):
|
if is_coroutine_callable(self.call):
|
||||||
return await cast(Callable[..., Awaitable[R]], self.call)(**values)
|
return await cast(Callable[..., Awaitable[R]], self.call)(**values)
|
||||||
else:
|
else:
|
||||||
return await run_sync(cast(Callable[..., R], self.call))(**values)
|
return await run_sync(cast(Callable[..., R], self.call))(**values)
|
||||||
|
except SkippedException as e:
|
||||||
|
logger.trace(f"{self} skipped due to {e}")
|
||||||
|
raise
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_params(
|
def parse_params(
|
||||||
@ -195,19 +199,10 @@ class Dependent(Generic[R]):
|
|||||||
return cls(call, params, parameterless_params)
|
return cls(call, params, parameterless_params)
|
||||||
|
|
||||||
async def check(self, **params: Any) -> None:
|
async def check(self, **params: Any) -> None:
|
||||||
try:
|
await asyncio.gather(*(param._check(**params) for param in self.parameterless))
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
*(param._check(**params) for param in self.parameterless)
|
*(cast(Param, param.field_info)._check(**params) for param in self.params)
|
||||||
)
|
)
|
||||||
await asyncio.gather(
|
|
||||||
*(
|
|
||||||
cast(Param, param.field_info)._check(**params)
|
|
||||||
for param in self.params
|
|
||||||
)
|
|
||||||
)
|
|
||||||
except SkippedException as e:
|
|
||||||
logger.trace(f"{self} skipped due to {e}")
|
|
||||||
raise
|
|
||||||
|
|
||||||
async def _solve_field(self, field: ModelField, params: Dict[str, Any]) -> Any:
|
async def _solve_field(self, field: ModelField, params: Dict[str, Any]) -> Any:
|
||||||
param = cast(Param, field.field_info)
|
param = cast(Param, field.field_info)
|
||||||
|
Loading…
Reference in New Issue
Block a user