Skip to content

Commit c8f3f47

Browse files
committed
Use builtins.dict instead of typing.Dict
1 parent 50e2b20 commit c8f3f47

File tree

4 files changed

+39
-39
lines changed

4 files changed

+39
-39
lines changed

libs/core/langchain_core/language_models/chat_models.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
from __future__ import annotations
44

55
import asyncio
6+
import builtins
67
import inspect
78
import json
8-
import typing
99
import warnings
1010
from abc import ABC, abstractmethod
1111
from collections.abc import AsyncIterator, Iterator, Sequence
@@ -366,7 +366,7 @@ class BaseChatModel(BaseLanguageModel[AIMessage], ABC):
366366

367367
@model_validator(mode="before")
368368
@classmethod
369-
def raise_deprecation(cls, values: typing.Dict) -> Any: # noqa: UP006
369+
def raise_deprecation(cls, values: builtins.dict) -> Any:
370370
"""Raise deprecation warning if ``callback_manager`` is used.
371371
372372
Args:
@@ -393,7 +393,7 @@ def raise_deprecation(cls, values: typing.Dict) -> Any: # noqa: UP006
393393
)
394394

395395
@cached_property
396-
def _serialized(self) -> typing.Dict[str, Any]: # noqa: UP006
396+
def _serialized(self) -> builtins.dict[str, Any]:
397397
return dumpd(self)
398398

399399
# --- Runnable methods ---
@@ -743,8 +743,8 @@ async def astream(
743743

744744
def _combine_llm_outputs(
745745
self,
746-
llm_outputs: list[Optional[typing.Dict]], # noqa: ARG002, UP006
747-
) -> typing.Dict: # noqa: UP006
746+
llm_outputs: list[Optional[builtins.dict]], # noqa: ARG002
747+
) -> builtins.dict:
748748
return {}
749749

750750
def _convert_cached_generations(self, cache_val: list) -> list[ChatGeneration]:
@@ -790,7 +790,7 @@ def _get_invocation_params(
790790
self,
791791
stop: Optional[list[str]] = None,
792792
**kwargs: Any,
793-
) -> typing.Dict: # noqa: UP006
793+
) -> builtins.dict:
794794
params = self.asdict()
795795
params["stop"] = stop
796796
return {**params, **kwargs}
@@ -854,7 +854,7 @@ def generate(
854854
callbacks: Callbacks = None,
855855
*,
856856
tags: Optional[list[str]] = None,
857-
metadata: Optional[typing.Dict[str, Any]] = None, # noqa: UP006
857+
metadata: Optional[builtins.dict[str, Any]] = None,
858858
run_name: Optional[str] = None,
859859
run_id: Optional[uuid.UUID] = None,
860860
**kwargs: Any,
@@ -969,7 +969,7 @@ async def agenerate(
969969
callbacks: Callbacks = None,
970970
*,
971971
tags: Optional[list[str]] = None,
972-
metadata: Optional[typing.Dict[str, Any]] = None, # noqa: UP006
972+
metadata: Optional[builtins.dict[str, Any]] = None,
973973
run_name: Optional[str] = None,
974974
run_id: Optional[uuid.UUID] = None,
975975
**kwargs: Any,
@@ -1542,20 +1542,18 @@ def _llm_type(self) -> str:
15421542

15431543
@deprecated("0.3.61", alternative="asdict", removal="1.0")
15441544
@override
1545-
def dict(self, **kwargs: Any) -> typing.Dict[str, Any]: # noqa: UP006
1545+
def dict(self, **kwargs: Any) -> builtins.dict[str, Any]:
15461546
return self.asdict()
15471547

1548-
def asdict(self) -> typing.Dict[str, Any]: # noqa: UP006
1548+
def asdict(self) -> builtins.dict[str, Any]:
15491549
"""Return a dictionary of the LLM."""
15501550
starter_dict = dict(self._identifying_params)
15511551
starter_dict["_type"] = self._llm_type
15521552
return starter_dict
15531553

15541554
def bind_tools(
15551555
self,
1556-
tools: Sequence[
1557-
Union[typing.Dict[str, Any], type, Callable, BaseTool] # noqa: UP006
1558-
],
1556+
tools: Sequence[Union[builtins.dict[str, Any], type, Callable, BaseTool]],
15591557
*,
15601558
tool_choice: Optional[Union[str]] = None,
15611559
**kwargs: Any,
@@ -1574,11 +1572,11 @@ def bind_tools(
15741572

15751573
def with_structured_output(
15761574
self,
1577-
schema: Union[typing.Dict, type], # noqa: UP006
1575+
schema: Union[builtins.dict, type],
15781576
*,
15791577
include_raw: bool = False,
15801578
**kwargs: Any,
1581-
) -> Runnable[LanguageModelInput, Union[typing.Dict, BaseModel]]: # noqa: UP006
1579+
) -> Runnable[LanguageModelInput, Union[builtins.dict, BaseModel]]:
15821580
"""Model wrapper that returns outputs formatted to match the given schema.
15831581
15841582
Args:

libs/core/langchain_core/language_models/llms.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from __future__ import annotations
44

55
import asyncio
6+
import builtins
67
import functools
78
import inspect
89
import json
910
import logging
10-
import typing
1111
import warnings
1212
from abc import ABC, abstractmethod
1313
from collections.abc import AsyncIterator, Iterator, Sequence
@@ -305,7 +305,7 @@ class BaseLLM(BaseLanguageModel[str], ABC):
305305

306306
@model_validator(mode="before")
307307
@classmethod
308-
def raise_deprecation(cls, values: typing.Dict[str, Any]) -> Any: # noqa: UP006
308+
def raise_deprecation(cls, values: builtins.dict[str, Any]) -> Any:
309309
"""Raise deprecation warning if callback_manager is used."""
310310
if values.get("callback_manager") is not None:
311311
warnings.warn(
@@ -317,7 +317,7 @@ def raise_deprecation(cls, values: typing.Dict[str, Any]) -> Any: # noqa: UP006
317317
return values
318318

319319
@functools.cached_property
320-
def _serialized(self) -> typing.Dict[str, Any]: # noqa: UP006
320+
def _serialized(self) -> builtins.dict[str, Any]:
321321
return dumpd(self)
322322

323323
# --- Runnable methods ---
@@ -821,7 +821,7 @@ def generate(
821821
*,
822822
tags: Optional[Union[list[str], list[list[str]]]] = None,
823823
metadata: Optional[
824-
Union[typing.Dict[str, Any], list[typing.Dict[str, Any]]] # noqa: UP006
824+
Union[builtins.dict[str, Any], list[builtins.dict[str, Any]]]
825825
] = None,
826826
run_name: Optional[Union[str, list[str]]] = None,
827827
run_id: Optional[Union[uuid.UUID, list[Optional[uuid.UUID]]]] = None,
@@ -1083,7 +1083,7 @@ async def agenerate(
10831083
*,
10841084
tags: Optional[Union[list[str], list[list[str]]]] = None,
10851085
metadata: Optional[
1086-
Union[typing.Dict[str, Any], list[typing.Dict[str, Any]]] # noqa: UP006
1086+
Union[builtins.dict[str, Any], list[builtins.dict[str, Any]]]
10871087
] = None,
10881088
run_name: Optional[Union[str, list[str]]] = None,
10891089
run_id: Optional[Union[uuid.UUID, list[Optional[uuid.UUID]]]] = None,
@@ -1285,7 +1285,7 @@ def __call__(
12851285
callbacks: Callbacks = None,
12861286
*,
12871287
tags: Optional[list[str]] = None,
1288-
metadata: Optional[typing.Dict[str, Any]] = None, # noqa: UP006
1288+
metadata: Optional[builtins.dict[str, Any]] = None,
12891289
**kwargs: Any,
12901290
) -> str:
12911291
"""Check Cache and run the LLM on the given prompt and input.
@@ -1334,7 +1334,7 @@ async def _call_async(
13341334
callbacks: Callbacks = None,
13351335
*,
13361336
tags: Optional[list[str]] = None,
1337-
metadata: Optional[typing.Dict[str, Any]] = None, # noqa: UP006
1337+
metadata: Optional[builtins.dict[str, Any]] = None,
13381338
**kwargs: Any,
13391339
) -> str:
13401340
"""Check Cache and run the LLM on the given prompt and input."""
@@ -1404,10 +1404,10 @@ def _llm_type(self) -> str:
14041404

14051405
@deprecated("0.3.61", alternative="asdict", removal="1.0")
14061406
@override
1407-
def dict(self, **kwargs: Any) -> typing.Dict[str, Any]: # noqa: UP006
1407+
def dict(self, **kwargs: Any) -> builtins.dict[str, Any]:
14081408
return self.asdict()
14091409

1410-
def asdict(self) -> typing.Dict[str, Any]: # noqa: UP006
1410+
def asdict(self) -> builtins.dict[str, Any]:
14111411
"""Return a dictionary of the LLM."""
14121412
starter_dict = dict(self._identifying_params)
14131413
starter_dict["_type"] = self._llm_type

libs/core/langchain_core/output_parsers/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from __future__ import annotations
44

5+
import builtins
56
import contextlib
6-
import typing
77
from abc import ABC, abstractmethod
88
from typing import (
99
TYPE_CHECKING,
@@ -329,10 +329,10 @@ def _type(self) -> str:
329329

330330
@deprecated("0.3.61", alternative="asdict", removal="1.0")
331331
@override
332-
def dict(self, **kwargs: Any) -> typing.Dict[str, Any]: # noqa: UP006
332+
def dict(self, **kwargs: Any) -> builtins.dict[str, Any]:
333333
return self.asdict()
334334

335-
def asdict(self, **kwargs: Any) -> typing.Dict[str, Any]: # noqa: UP006
335+
def asdict(self, **kwargs: Any) -> builtins.dict[str, Any]:
336336
"""Return dictionary representation of output parser."""
337337
output_parser_dict = super().model_dump(**kwargs)
338338
with contextlib.suppress(NotImplementedError):

libs/core/langchain_core/prompts/base.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from __future__ import annotations
44

5+
import builtins
56
import contextlib
67
import json
7-
import typing
88
from abc import ABC, abstractmethod
99
from collections.abc import Mapping
1010
from functools import cached_property
@@ -55,7 +55,7 @@ class BasePromptTemplate(
5555
"""optional_variables: A list of the names of the variables for placeholder
5656
or MessagePlaceholder that are optional. These variables are auto inferred
5757
from the prompt and user need not provide them."""
58-
input_types: typing.Dict[str, Any] = Field(default_factory=dict, exclude=True) # noqa: UP006
58+
input_types: builtins.dict[str, Any] = Field(default_factory=dict, exclude=True)
5959
"""A dictionary of the types of the variables the prompt template expects.
6060
If not provided, all variables are assumed to be strings."""
6161
output_parser: Optional[BaseOutputParser] = None
@@ -65,7 +65,7 @@ class BasePromptTemplate(
6565
6666
Partial variables populate the template so that you don't need to
6767
pass them in every time you call the prompt."""
68-
metadata: Optional[typing.Dict[str, Any]] = None # noqa: UP006
68+
metadata: Optional[builtins.dict[str, Any]] = None
6969
"""Metadata to be used for tracing."""
7070
tags: Optional[list[str]] = None
7171
"""Tags to be used for tracing."""
@@ -119,7 +119,7 @@ def is_lc_serializable(cls) -> bool:
119119
)
120120

121121
@cached_property
122-
def _serialized(self) -> typing.Dict[str, Any]: # noqa: UP006
122+
def _serialized(self) -> builtins.dict[str, Any]:
123123
return dumpd(self)
124124

125125
@property
@@ -152,7 +152,7 @@ def get_input_schema(
152152
field_definitions={**required_input_variables, **optional_input_variables},
153153
)
154154

155-
def _validate_input(self, inner_input: Any) -> typing.Dict: # noqa: UP006
155+
def _validate_input(self, inner_input: Any) -> builtins.dict:
156156
if not isinstance(inner_input, dict):
157157
if len(self.input_variables) == 1:
158158
var_name = self.input_variables[0]
@@ -188,22 +188,22 @@ def _validate_input(self, inner_input: Any) -> typing.Dict: # noqa: UP006
188188

189189
def _format_prompt_with_error_handling(
190190
self,
191-
inner_input: typing.Dict, # noqa: UP006
191+
inner_input: builtins.dict,
192192
) -> PromptValue:
193193
inner_input_ = self._validate_input(inner_input)
194194
return self.format_prompt(**inner_input_)
195195

196196
async def _aformat_prompt_with_error_handling(
197197
self,
198-
inner_input: typing.Dict, # noqa: UP006
198+
inner_input: builtins.dict,
199199
) -> PromptValue:
200200
inner_input_ = self._validate_input(inner_input)
201201
return await self.aformat_prompt(**inner_input_)
202202

203203
@override
204204
def invoke(
205205
self,
206-
input: typing.Dict, # noqa: UP006
206+
input: builtins.dict,
207207
config: Optional[RunnableConfig] = None,
208208
**kwargs: Any,
209209
) -> PromptValue:
@@ -232,7 +232,7 @@ def invoke(
232232
@override
233233
async def ainvoke(
234234
self,
235-
input: typing.Dict, # noqa: UP006
235+
input: builtins.dict,
236236
config: Optional[RunnableConfig] = None,
237237
**kwargs: Any,
238238
) -> PromptValue:
@@ -296,7 +296,9 @@ def partial(self, **kwargs: Union[str, Callable[[], str]]) -> BasePromptTemplate
296296
prompt_dict["partial_variables"] = {**self.partial_variables, **kwargs}
297297
return type(self)(**prompt_dict)
298298

299-
def _merge_partial_and_user_variables(self, **kwargs: Any) -> typing.Dict[str, Any]: # noqa: UP006
299+
def _merge_partial_and_user_variables(
300+
self, **kwargs: Any
301+
) -> builtins.dict[str, Any]:
300302
# Get partial params:
301303
partial_kwargs = {
302304
k: v if not callable(v) else v() for k, v in self.partial_variables.items()
@@ -346,10 +348,10 @@ def _prompt_type(self) -> str:
346348

347349
@deprecated("0.3.61", alternative="asdict", removal="1.0")
348350
@override
349-
def dict(self, **kwargs: Any) -> typing.Dict[str, Any]: # noqa: UP006
351+
def dict(self, **kwargs: Any) -> builtins.dict[str, Any]:
350352
return self.asdict(**kwargs)
351353

352-
def asdict(self, **kwargs: Any) -> typing.Dict[str, Any]: # noqa: UP006
354+
def asdict(self, **kwargs: Any) -> builtins.dict[str, Any]:
353355
"""Return dictionary representation of prompt.
354356
355357
Args:

0 commit comments

Comments
 (0)