1010from nonebot .dependencies import Param
1111from nonebot .internal .adapter import Bot , Event
1212from nonebot .internal .matcher import Matcher
13- from nonebot .internal .params import Depends
14- from nonebot .typing import T_DependencyCache , T_State
13+ from nonebot .internal .params import DependencyCache , Depends
14+ from nonebot .typing import T_State , _DependentCallable
1515from nonebot .utils import generic_check_issubclass
1616from tarina import run_always_await
17- from tarina .generic import get_origin
17+ from tarina .generic import get_origin , is_optional
1818
1919from .consts import ALCONNA_ARG_KEY , ALCONNA_ARG_KEYS , ALCONNA_EXEC_RESULT , ALCONNA_EXTENSION , ALCONNA_RESULT
2020from .extension import Extension , ExtensionExecutor , SelectedExtensions
@@ -367,8 +367,10 @@ def __repr__(self) -> str:
367367 def _check_param (cls , param : inspect .Parameter , allow_types : tuple [type [Param ], ...]) -> Optional [Self ]:
368368 if param .annotation == AsyncExitStack :
369369 return cls (..., type = AsyncExitStack )
370+ if param .annotation == Optional [AsyncExitStack ]:
371+ return cls (None , type = AsyncExitStack )
370372 if generic_check_issubclass (param .annotation , AsyncExitStack ):
371- return cls (... , type = AsyncExitStack , default = None )
373+ return cls (None , type = AsyncExitStack )
372374
373375 @override
374376 async def _solve (self , stack : Optional [AsyncExitStack ] = None , ** kwargs : Any ) -> Any :
@@ -387,11 +389,15 @@ def __repr__(self) -> str:
387389 @classmethod
388390 @override
389391 def _check_param (cls , param : inspect .Parameter , allow_types : tuple [type [Param ], ...]) -> Optional [Self ]:
390- if param .annotation == T_DependencyCache :
391- return cls (..., type = T_DependencyCache )
392- if generic_check_issubclass (param .annotation , T_DependencyCache ):
393- return cls (..., type = T_DependencyCache , default = None )
392+ if param .annotation == dict [_DependentCallable [Any ], DependencyCache ]:
393+ return cls (..., type = dict [_DependentCallable [Any ], DependencyCache ])
394+ if param .annotation == Optional [dict [_DependentCallable [Any ], DependencyCache ]]:
395+ return cls (None , type = dict [_DependentCallable [Any ], DependencyCache ])
396+ if is_optional (param .annotation , dict [_DependentCallable [Any ], DependencyCache ]):
397+ return cls (None , type = dict [_DependentCallable [Any ], DependencyCache ])
394398
395399 @override
396- async def _solve (self , dependency_cache : Optional [T_DependencyCache ] = None , ** kwargs : Any ) -> Any :
400+ async def _solve (
401+ self , dependency_cache : Optional [dict [_DependentCallable [Any ], DependencyCache ]] = None , ** kwargs : Any
402+ ) -> Any :
397403 return dependency_cache
0 commit comments