🐛 fix event maybe converted when checking type (#876)

Fix: 修复 event 类型检查会对类型进行自动转换
This commit is contained in:
Ju4tCode
2022-03-20 19:40:43 +08:00
committed by GitHub
parent fcdb05a7e2
commit 45e2e6c280
6 changed files with 53 additions and 20 deletions

View File

@ -9,7 +9,6 @@ from pydantic.fields import Required, Undefined, ModelField
from nonebot.log import logger
from nonebot.exception import TypeMisMatch
from nonebot.dependencies.utils import check_field_type
from nonebot.dependencies import Param, Dependent, CustomConfig
from nonebot.typing import T_State, T_Handler, T_DependencyCache
from nonebot.utils import (
@ -160,14 +159,14 @@ class DependParam(Param):
class _BotChecker(Param):
async def _solve(self, bot: "Bot", **kwargs: Any) -> Any:
field: ModelField = self.extra["field"]
try:
return check_field_type(field, bot)
except TypeMisMatch:
if isinstance(bot, field.type_):
return bot
else:
logger.debug(
f"Bot type {type(bot)} not match "
f"annotation {field._type_display()}, ignored"
)
raise
raise TypeMisMatch(field, bot)
class BotParam(Param):
@ -206,14 +205,14 @@ class BotParam(Param):
class _EventChecker(Param):
async def _solve(self, event: "Event", **kwargs: Any) -> Any:
field: ModelField = self.extra["field"]
try:
return check_field_type(field, event)
except TypeMisMatch:
if isinstance(event, field.type_):
return event
else:
logger.debug(
f"Event type {type(event)} not match "
f"annotation {field._type_display()}, ignored"
)
raise
raise TypeMisMatch(field, event)
class EventParam(Param):