Skip to content

Commit 41b5223

Browse files
committed
Use rather than for variable names
1 parent f82f89b commit 41b5223

File tree

4 files changed

+51
-49
lines changed

4 files changed

+51
-49
lines changed

libs/core/langchain_core/runnables/base.py

+31-29
Original file line numberDiff line numberDiff line change
@@ -778,14 +778,14 @@ def batch(
778778

779779
configs = get_config_list(config, len(inputs))
780780

781-
def invoke(value: Input, config: RunnableConfig) -> Union[Output, Exception]:
781+
def invoke(input_: Input, config: RunnableConfig) -> Union[Output, Exception]:
782782
if return_exceptions:
783783
try:
784-
return self.invoke(value, config, **kwargs)
784+
return self.invoke(input_, config, **kwargs)
785785
except Exception as e:
786786
return e
787787
else:
788-
return self.invoke(value, config, **kwargs)
788+
return self.invoke(input_, config, **kwargs)
789789

790790
# If there's only one input, don't bother with the executor
791791
if len(inputs) == 1:
@@ -832,15 +832,17 @@ def batch_as_completed(
832832
configs = get_config_list(config, len(inputs))
833833

834834
def invoke(
835-
i: int, value: Input, config: RunnableConfig
835+
i: int, input_: Input, config: RunnableConfig
836836
) -> tuple[int, Union[Output, Exception]]:
837837
if return_exceptions:
838838
try:
839-
out: Union[Output, Exception] = self.invoke(value, config, **kwargs)
839+
out: Union[Output, Exception] = self.invoke(
840+
input_, config, **kwargs
841+
)
840842
except Exception as e:
841843
out = e
842844
else:
843-
out = self.invoke(value, config, **kwargs)
845+
out = self.invoke(input_, config, **kwargs)
844846

845847
return (i, out)
846848

@@ -966,24 +968,24 @@ async def abatch_as_completed(
966968
semaphore = asyncio.Semaphore(max_concurrency) if max_concurrency else None
967969

968970
async def ainvoke_task(
969-
i: int, value: Input, config: RunnableConfig
971+
i: int, input_: Input, config: RunnableConfig
970972
) -> tuple[int, Union[Output, Exception]]:
971973
if return_exceptions:
972974
try:
973975
out: Union[Output, Exception] = await self.ainvoke(
974-
value, config, **kwargs
976+
input_, config, **kwargs
975977
)
976978
except Exception as e:
977979
out = e
978980
else:
979-
out = await self.ainvoke(value, config, **kwargs)
981+
out = await self.ainvoke(input_, config, **kwargs)
980982
return (i, out)
981983

982984
coros = [
983-
gated_coro(semaphore, ainvoke_task(i, value, config))
985+
gated_coro(semaphore, ainvoke_task(i, input_, config))
984986
if semaphore
985-
else ainvoke_task(i, value, config)
986-
for i, (value, config) in enumerate(zip(inputs, configs))
987+
else ainvoke_task(i, input_, config)
988+
for i, (input_, config) in enumerate(zip(inputs, configs))
987989
]
988990

989991
for coro in asyncio.as_completed(coros):
@@ -1909,7 +1911,7 @@ def _call_with_config(
19091911
Callable[[Input, CallbackManagerForChainRun], Output],
19101912
Callable[[Input, CallbackManagerForChainRun, RunnableConfig], Output],
19111913
],
1912-
value: Input,
1914+
input_: Input,
19131915
config: Optional[RunnableConfig],
19141916
run_type: Optional[str] = None,
19151917
serialized: Optional[dict[str, Any]] = None,
@@ -1923,7 +1925,7 @@ def _call_with_config(
19231925
callback_manager = get_callback_manager_for_config(config)
19241926
run_manager = callback_manager.on_chain_start(
19251927
serialized,
1926-
value,
1928+
input_,
19271929
run_type=run_type,
19281930
name=config.get("run_name") or self.get_name(),
19291931
run_id=config.pop("run_id", None),
@@ -1936,7 +1938,7 @@ def _call_with_config(
19361938
context.run(
19371939
call_func_with_variable_args, # type: ignore[arg-type]
19381940
func,
1939-
value,
1941+
input_,
19401942
config,
19411943
run_manager,
19421944
**kwargs,
@@ -1959,7 +1961,7 @@ async def _acall_with_config(
19591961
Awaitable[Output],
19601962
],
19611963
],
1962-
value: Input,
1964+
input_: Input,
19631965
config: Optional[RunnableConfig],
19641966
run_type: Optional[str] = None,
19651967
serialized: Optional[dict[str, Any]] = None,
@@ -1973,7 +1975,7 @@ async def _acall_with_config(
19731975
callback_manager = get_async_callback_manager_for_config(config)
19741976
run_manager = await callback_manager.on_chain_start(
19751977
serialized,
1976-
value,
1978+
input_,
19771979
run_type=run_type,
19781980
name=config.get("run_name") or self.get_name(),
19791981
run_id=config.pop("run_id", None),
@@ -1982,7 +1984,7 @@ async def _acall_with_config(
19821984
child_config = patch_config(config, callbacks=run_manager.get_child())
19831985
with set_config_context(child_config) as context:
19841986
coro = acall_func_with_variable_args(
1985-
func, value, config, run_manager, **kwargs
1987+
func, input_, config, run_manager, **kwargs
19861988
)
19871989
output: Output = await coro_with_context(coro, context)
19881990
except BaseException as e:
@@ -3741,7 +3743,7 @@ def invoke(
37413743
)
37423744

37433745
def _invoke_step(
3744-
step: Runnable[Input, Any], value: Input, config: RunnableConfig, key: str
3746+
step: Runnable[Input, Any], input_: Input, config: RunnableConfig, key: str
37453747
) -> Any:
37463748
child_config = patch_config(
37473749
config,
@@ -3751,7 +3753,7 @@ def _invoke_step(
37513753
with set_config_context(child_config) as context:
37523754
return context.run(
37533755
step.invoke,
3754-
value,
3756+
input_,
37553757
child_config,
37563758
)
37573759

@@ -3793,15 +3795,15 @@ async def ainvoke(
37933795
)
37943796

37953797
async def _ainvoke_step(
3796-
step: Runnable[Input, Any], value: Input, config: RunnableConfig, key: str
3798+
step: Runnable[Input, Any], input_: Input, config: RunnableConfig, key: str
37973799
) -> Any:
37983800
child_config = patch_config(
37993801
config,
38003802
callbacks=run_manager.get_child(f"map:key:{key}"),
38013803
)
38023804
with set_config_context(child_config) as context:
38033805
return await coro_with_context(
3804-
step.ainvoke(value, child_config), context, create_task=True
3806+
step.ainvoke(input_, child_config), context, create_task=True
38053807
)
38063808

38073809
# gather results from all steps
@@ -4598,7 +4600,7 @@ def __repr__(self) -> str:
45984600

45994601
def _invoke(
46004602
self,
4601-
value: Input,
4603+
input_: Input,
46024604
run_manager: CallbackManagerForChainRun,
46034605
config: RunnableConfig,
46044606
**kwargs: Any,
@@ -4607,7 +4609,7 @@ def _invoke(
46074609
output: Optional[Output] = None
46084610
for chunk in call_func_with_variable_args(
46094611
cast("Callable[[Input], Iterator[Output]]", self.func),
4610-
value,
4612+
input_,
46114613
config,
46124614
run_manager,
46134615
**kwargs,
@@ -4621,18 +4623,18 @@ def _invoke(
46214623
output = chunk
46224624
else:
46234625
output = call_func_with_variable_args(
4624-
self.func, value, config, run_manager, **kwargs
4626+
self.func, input_, config, run_manager, **kwargs
46254627
)
46264628
# If the output is a Runnable, invoke it
46274629
if isinstance(output, Runnable):
46284630
recursion_limit = config["recursion_limit"]
46294631
if recursion_limit <= 0:
46304632
msg = (
4631-
f"Recursion limit reached when invoking {self} with input {value}."
4633+
f"Recursion limit reached when invoking {self} with input {input_}."
46324634
)
46334635
raise RecursionError(msg)
46344636
output = output.invoke(
4635-
value,
4637+
input_,
46364638
patch_config(
46374639
config,
46384640
callbacks=run_manager.get_child(),
@@ -4921,13 +4923,13 @@ async def _atransform(
49214923
raise TypeError(msg)
49224924

49234925
def func(
4924-
value: Input,
4926+
input_: Input,
49254927
run_manager: AsyncCallbackManagerForChainRun,
49264928
config: RunnableConfig,
49274929
**kwargs: Any,
49284930
) -> Output:
49294931
return call_func_with_variable_args(
4930-
self.func, value, config, run_manager.get_sync(), **kwargs
4932+
self.func, input_, config, run_manager.get_sync(), **kwargs
49314933
)
49324934

49334935
@wraps(func)

libs/core/langchain_core/runnables/configurable.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,16 @@ def batch(
178178

179179
def invoke(
180180
prepared: tuple[Runnable[Input, Output], RunnableConfig],
181-
value: Input,
181+
input_: Input,
182182
) -> Union[Output, Exception]:
183183
bound, config = prepared
184184
if return_exceptions:
185185
try:
186-
return bound.invoke(value, config, **kwargs)
186+
return bound.invoke(input_, config, **kwargs)
187187
except Exception as e:
188188
return e
189189
else:
190-
return bound.invoke(value, config, **kwargs)
190+
return bound.invoke(input_, config, **kwargs)
191191

192192
# If there's only one input, don't bother with the executor
193193
if len(inputs) == 1:
@@ -221,16 +221,16 @@ async def abatch(
221221

222222
async def ainvoke(
223223
prepared: tuple[Runnable[Input, Output], RunnableConfig],
224-
value: Input,
224+
input_: Input,
225225
) -> Union[Output, Exception]:
226226
bound, config = prepared
227227
if return_exceptions:
228228
try:
229-
return await bound.ainvoke(value, config, **kwargs)
229+
return await bound.ainvoke(input_, config, **kwargs)
230230
except Exception as e:
231231
return e
232232
else:
233-
return await bound.ainvoke(value, config, **kwargs)
233+
return await bound.ainvoke(input_, config, **kwargs)
234234

235235
coros = map(ainvoke, prepared, inputs)
236236
return await gather_with_concurrency(configs[0].get("max_concurrency"), *coros)

libs/core/langchain_core/runnables/retry.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,15 @@ def _patch_config_list(
178178

179179
def _invoke(
180180
self,
181-
value: Input,
181+
input_: Input,
182182
run_manager: "CallbackManagerForChainRun",
183183
config: RunnableConfig,
184184
**kwargs: Any,
185185
) -> Output:
186186
for attempt in self._sync_retrying(reraise=True):
187187
with attempt:
188188
result = super().invoke(
189-
value,
189+
input_,
190190
self._patch_config(config, run_manager, attempt.retry_state),
191191
**kwargs,
192192
)
@@ -202,15 +202,15 @@ def invoke(
202202

203203
async def _ainvoke(
204204
self,
205-
value: Input,
205+
input_: Input,
206206
run_manager: "AsyncCallbackManagerForChainRun",
207207
config: RunnableConfig,
208208
**kwargs: Any,
209209
) -> Output:
210210
async for attempt in self._async_retrying(reraise=True):
211211
with attempt:
212212
result = await super().ainvoke(
213-
value,
213+
input_,
214214
self._patch_config(config, run_manager, attempt.retry_state),
215215
**kwargs,
216216
)

libs/core/langchain_core/runnables/router.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -148,22 +148,22 @@ def batch(
148148
if not inputs:
149149
return []
150150

151-
keys = [value["key"] for value in inputs]
152-
actual_inputs = [value["input"] for value in inputs]
151+
keys = [input_["key"] for input_ in inputs]
152+
actual_inputs = [input_["input"] for input_ in inputs]
153153
if any(key not in self.runnables for key in keys):
154154
msg = "One or more keys do not have a corresponding runnable"
155155
raise ValueError(msg)
156156

157157
def invoke(
158-
runnable: Runnable, value: Input, config: RunnableConfig
158+
runnable: Runnable, input_: Input, config: RunnableConfig
159159
) -> Union[Output, Exception]:
160160
if return_exceptions:
161161
try:
162-
return runnable.invoke(value, config, **kwargs)
162+
return runnable.invoke(input_, config, **kwargs)
163163
except Exception as e:
164164
return e
165165
else:
166-
return runnable.invoke(value, config, **kwargs)
166+
return runnable.invoke(input_, config, **kwargs)
167167

168168
runnables = [self.runnables[key] for key in keys]
169169
configs = get_config_list(config, len(inputs))
@@ -185,22 +185,22 @@ async def abatch(
185185
if not inputs:
186186
return []
187187

188-
keys = [value["key"] for value in inputs]
189-
actual_inputs = [value["input"] for value in inputs]
188+
keys = [input_["key"] for input_ in inputs]
189+
actual_inputs = [input_["input"] for input_ in inputs]
190190
if any(key not in self.runnables for key in keys):
191191
msg = "One or more keys do not have a corresponding runnable"
192192
raise ValueError(msg)
193193

194194
async def ainvoke(
195-
runnable: Runnable, value: Input, config: RunnableConfig
195+
runnable: Runnable, input_: Input, config: RunnableConfig
196196
) -> Union[Output, Exception]:
197197
if return_exceptions:
198198
try:
199-
return await runnable.ainvoke(value, config, **kwargs)
199+
return await runnable.ainvoke(input_, config, **kwargs)
200200
except Exception as e:
201201
return e
202202
else:
203-
return await runnable.ainvoke(value, config, **kwargs)
203+
return await runnable.ainvoke(input_, config, **kwargs)
204204

205205
runnables = [self.runnables[key] for key in keys]
206206
configs = get_config_list(config, len(inputs))

0 commit comments

Comments
 (0)