Skip to content

Commit bd7ecc3

Browse files
committed
chore: Improve variable names and docstring for more clarity
1 parent 2f25fe5 commit bd7ecc3

File tree

1 file changed

+21
-9
lines changed
  • packages/toolbox-core/src/toolbox_core

1 file changed

+21
-9
lines changed

packages/toolbox-core/src/toolbox_core/tool.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from inspect import Signature
1919
from typing import (
2020
Any,
21+
Awaitable,
2122
Callable,
2223
Iterable,
2324
Mapping,
@@ -181,12 +182,12 @@ async def __call__(self, *args: Any, **kwargs: Any) -> str:
181182

182183
# apply bounded parameters
183184
for param, value in self.__bound_parameters.items():
184-
payload[param] = await get_value(value)
185+
payload[param] = await resolve_value(value)
185186

186187
# create headers for auth services
187188
headers = {}
188189
for auth_service, token_getter in self.__auth_service_token_getters.items():
189-
headers[f"{auth_service}_token"] = await get_value(token_getter)
190+
headers[f"{auth_service}_token"] = await resolve_value(token_getter)
190191

191192
async with self.__session.post(
192193
self.__url,
@@ -328,10 +329,21 @@ def params_to_pydantic_model(
328329
return create_model(tool_name, **field_definitions)
329330

330331

331-
async def get_value(func: Callable[[], Any]) -> Any:
332-
"""Asynchronously or synchronously gets the value from a callable."""
333-
if asyncio.iscoroutinefunction(func):
334-
return await func()
335-
elif callable(func):
336-
return func()
337-
return func
332+
async def resolve_value(
333+
source: Union[Callable[[], Awaitable[Any]], Callable[[], Any], Any],
334+
) -> Any:
335+
"""
336+
Asynchronously or synchronously resolves a given source to its value.
337+
338+
Args:
339+
source: The value, a callable returning a value, or a callable
340+
returning an awaitable value.
341+
342+
Returns:
343+
The resolved value.
344+
"""
345+
if asyncio.iscoroutinefunction(source):
346+
return await source()
347+
elif callable(source):
348+
return source()
349+
return source

0 commit comments

Comments
 (0)