88from dataclasses import dataclass
99from functools import wraps
1010from inspect import Parameter
11- from typing import Any , Callable , Literal , Mapping , Optional , Sequence , TypeVar , TypedDict , Union
11+ from typing import Any , Awaitable , Callable , Coroutine , Literal , Mapping , Optional , Sequence , TypeVar , TypedDict , Union
1212from typing_extensions import ParamSpec
1313
1414from opentelemetry .trace import Tracer
@@ -114,7 +114,7 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> Optional[R]:
114114 return func_output
115115
116116 @wraps (func )
117- async def async_wrapper (* args : P .args , ** kwargs : P .kwargs ) -> Optional [R ]:
117+ async def async_wrapper (* args : P .args , ** kwargs : P .kwargs ) -> Awaitable [ Optional [R ] ]:
118118 evaluation_context = get_evaluation_context ()
119119 if evaluation_context is not None :
120120 if evaluation_context .path == path :
@@ -135,7 +135,8 @@ async def async_wrapper(*args: P.args, **kwargs: P.kwargs) -> Optional[R]:
135135
136136 func_output : Optional [R ]
137137 try :
138- func_output = await func (* args , ** kwargs )
138+ # Polymorphic decorator does not recognize the function is a coroutine
139+ func_output = await func (* args , ** kwargs ) # type: ignore [misc]
139140 log_output = process_output (
140141 func = func ,
141142 output = func_output ,
@@ -168,7 +169,8 @@ async def async_wrapper(*args: P.args, **kwargs: P.kwargs) -> Optional[R]:
168169 )
169170
170171 # Return the output of the decorated function
171- return func_output
172+ # Polymorphic decorator does not recognize the function is a coroutine
173+ return func_output # type: ignore [return-value]
172174
173175 # If the decorated function is an async function, return the async wrapper
174176 if asyncio .iscoroutinefunction (func ):
@@ -178,7 +180,8 @@ async def async_wrapper(*args: P.args, **kwargs: P.kwargs) -> Optional[R]:
178180 version = tool_kernel ,
179181 callable = async_wrapper ,
180182 )
181- return async_wrapper
183+ # Polymorphic decorator does not recognize the function is a coroutine
184+ return async_wrapper # type: ignore [return-value]
182185
183186 # If the decorated function is a sync function, return the sync wrapper
184187 wrapper .file = File ( # type: ignore
0 commit comments