mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-16 19:11:00 +00:00
🐛 fix event maybe converted when checking type (#876)
Fix: 修复 event 类型检查会对类型进行自动转换
This commit is contained in:
@ -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):
|
||||
|
Reference in New Issue
Block a user