Skip to content

Commit 2ff07d1

Browse files
committed
feat: Add bind_param (singular) to align with other packages
1 parent a36ae42 commit 2ff07d1

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,31 @@ def bind_params(
159159
"""
160160
Binds parameters to values or callables that produce values.
161161
162-
Args:
163-
bound_params: A mapping of parameter names to values or callables that
164-
produce values.
162+
Args:
163+
bound_params: A mapping of parameter names to values or callables that
164+
produce values.
165165
166-
Returns:
167-
A new ToolboxSyncTool instance with the specified parameters bound.
166+
Returns:
167+
A new ToolboxSyncTool instance with the specified parameters bound.
168168
"""
169169

170170
new_async_tool = self.__async_tool.bind_params(bound_params)
171171
return ToolboxSyncTool(new_async_tool, self.__loop, self.__thread)
172+
173+
def bind_param(
174+
self,
175+
param_name: str,
176+
param_value: Union[Callable[[], Any], Any],
177+
) -> "ToolboxTool":
178+
"""
179+
Binds a parameter to the value or callables that produce it.
180+
181+
Args:
182+
param_name: The name of the bound parameter.
183+
param_value: The value of the bound parameter, or a callable that
184+
returns the value.
185+
186+
Returns:
187+
A new ToolboxSyncTool instance with the specified parameter bound.
188+
"""
189+
return self.bind_params({param_name: param_value})

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,12 @@ def bind_params(
307307
"""
308308
Binds parameters to values or callables that produce values.
309309
310-
Args:
311-
bound_params: A mapping of parameter names to values or callables that
312-
produce values.
310+
Args:
311+
bound_params: A mapping of parameter names to values or callables that
312+
produce values.
313313
314-
Returns:
315-
A new ToolboxTool instance with the specified parameters bound.
314+
Returns:
315+
A new ToolboxTool instance with the specified parameters bound.
316316
"""
317317
param_names = set(p.name for p in self.__params)
318318
for name in bound_params.keys():
@@ -335,3 +335,21 @@ def bind_params(
335335
params=new_params,
336336
bound_params=MappingProxyType(all_bound_params),
337337
)
338+
339+
def bind_param(
340+
self,
341+
param_name: str,
342+
param_value: Union[Callable[[], Any], Any],
343+
) -> "ToolboxTool":
344+
"""
345+
Binds a parameter to the value or callables that produce it.
346+
347+
Args:
348+
param_name: The name of the bound parameter.
349+
param_value: The value of the bound parameter, or a callable that
350+
returns the value.
351+
352+
Returns:
353+
A new ToolboxTool instance with the specified parameters bound.
354+
"""
355+
return self.bind_params({param_name: param_value})

0 commit comments

Comments
 (0)