Skip to content

Commit 8f08b84

Browse files
committed
feat: Add bind_param (singular) to align with other packages
1 parent 66f86a4 commit 8f08b84

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
@@ -130,13 +130,31 @@ def bind_params(
130130
"""
131131
Binds parameters to values or callables that produce values.
132132
133-
Args:
134-
bound_params: A mapping of parameter names to values or callables that
135-
produce values.
133+
Args:
134+
bound_params: A mapping of parameter names to values or callables that
135+
produce values.
136136
137-
Returns:
138-
A new ToolboxSyncTool instance with the specified parameters bound.
137+
Returns:
138+
A new ToolboxSyncTool instance with the specified parameters bound.
139139
"""
140140

141141
new_async_tool = self.__async_tool.bind_params(bound_params)
142142
return ToolboxSyncTool(new_async_tool, self.__loop, self.__thread)
143+
144+
def bind_param(
145+
self,
146+
param_name: str,
147+
param_value: Union[Callable[[], Any], Any],
148+
) -> "ToolboxTool":
149+
"""
150+
Binds a parameter to the value or callables that produce it.
151+
152+
Args:
153+
param_name: The name of the bound parameter.
154+
param_value: The value of the bound parameter, or a callable that
155+
returns the value.
156+
157+
Returns:
158+
A new ToolboxSyncTool instance with the specified parameter bound.
159+
"""
160+
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
@@ -279,12 +279,12 @@ def bind_params(
279279
"""
280280
Binds parameters to values or callables that produce values.
281281
282-
Args:
283-
bound_params: A mapping of parameter names to values or callables that
284-
produce values.
282+
Args:
283+
bound_params: A mapping of parameter names to values or callables that
284+
produce values.
285285
286-
Returns:
287-
A new ToolboxTool instance with the specified parameters bound.
286+
Returns:
287+
A new ToolboxTool instance with the specified parameters bound.
288288
"""
289289
param_names = set(p.name for p in self.__params)
290290
for name in bound_params.keys():
@@ -307,3 +307,21 @@ def bind_params(
307307
params=new_params,
308308
bound_params=types.MappingProxyType(all_bound_params),
309309
)
310+
311+
def bind_param(
312+
self,
313+
param_name: str,
314+
param_value: Union[Callable[[], Any], Any],
315+
) -> "ToolboxTool":
316+
"""
317+
Binds a parameter to the value or callables that produce it.
318+
319+
Args:
320+
param_name: The name of the bound parameter.
321+
param_value: The value of the bound parameter, or a callable that
322+
returns the value.
323+
324+
Returns:
325+
A new ToolboxTool instance with the specified parameters bound.
326+
"""
327+
return self.bind_params({param_name: param_value})

0 commit comments

Comments
 (0)