@@ -57,7 +57,7 @@ def __init__(
5757 self .decorator_name = decorator_name
5858 self .frame = frame
5959 self .base_object : Optional [SomeClassInstance ] = None # type: ignore[valid-type]
60- self .cache : Dict [str , Callable ] = {}
60+ self .cache : Dict [str , Callable [ FunctionParams , ReturnType ] ] = {}
6161
6262 def __call__ (self , * args : Any , ** kwargs : Any ) -> None :
6363 raise CallTransfunctionDirectlyError ("You can't call a transfunction object directly, create a function, a generator function or a coroutine function from it." )
@@ -71,13 +71,13 @@ def __get__(
7171 return self
7272
7373 @staticmethod
74- def is_lambda (function : Callable ) -> bool :
74+ def is_lambda (function : Callable [ FunctionParams , ReturnType ] ) -> bool :
7575 # https://stackoverflow.com/a/3655857/14522393
7676 lambda_example = lambda : 0 # noqa: E731
7777 return isinstance (function , type (lambda_example )) and function .__name__ == lambda_example .__name__
7878
7979 def get_usual_function (self , addictional_transformers : Optional [List [NodeTransformer ]] = None ) -> Callable [FunctionParams , ReturnType ]:
80- return self .extract_context ('sync_context' , addictional_transformers = addictional_transformers )
80+ return cast ( Callable [ FunctionParams , ReturnType ], self .extract_context ('sync_context' , addictional_transformers = addictional_transformers ) )
8181
8282 def get_async_function (self ) -> Callable [FunctionParams , Coroutine [Any , Any , ReturnType ]]:
8383 original_function = self .function
@@ -112,12 +112,15 @@ def visit_Call(self, node: Call) -> Union[Call, Await]:
112112 )
113113 return node
114114
115- return self .extract_context (
116- 'async_context' ,
117- addictional_transformers = [
118- ConvertSyncFunctionToAsync (),
119- ExtractAwaitExpressions (),
120- ],
115+ return cast (
116+ Callable [FunctionParams , Coroutine [Any , Any , ReturnType ]],
117+ self .extract_context (
118+ 'async_context' ,
119+ addictional_transformers = [
120+ ConvertSyncFunctionToAsync (),
121+ ExtractAwaitExpressions (),
122+ ],
123+ ),
121124 )
122125
123126 def get_generator_function (self ) -> Callable [FunctionParams , Generator [ReturnType , None , None ]]:
@@ -136,11 +139,14 @@ def visit_Call(self, node: Call) -> Optional[Union[AST, List[AST]]]:
136139 )
137140 return node
138141
139- return self .extract_context (
140- 'generator_context' ,
141- addictional_transformers = [
142- ConvertYieldFroms (),
143- ],
142+ return cast (
143+ Callable [FunctionParams , Generator [ReturnType , None , None ]],
144+ self .extract_context (
145+ 'generator_context' ,
146+ addictional_transformers = [
147+ ConvertYieldFroms (),
148+ ],
149+ ),
144150 )
145151
146152 @staticmethod
@@ -159,7 +165,7 @@ def clear_spaces_from_source_code(source_code: str) -> str:
159165 return '\n ' .join (new_splitted_source_code )
160166
161167
162- def extract_context (self , context_name : str , addictional_transformers : Optional [List [NodeTransformer ]] = None ):
168+ def extract_context (self , context_name : str , addictional_transformers : Optional [List [NodeTransformer ]] = None ) -> Callable [ FunctionParams , Union [ Coroutine [ Any , Any , ReturnType ], Generator [ ReturnType , None , None ], ReturnType ]] :
163169 if context_name in self .cache :
164170 return self .cache [context_name ]
165171 try :
0 commit comments