_replace_type_vars() — langchain Function Reference
Architecture documentation for the _replace_type_vars() function in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD bd94b6bb_a9a9_4c3a_20e5_3bb8b57e2eaf["_replace_type_vars()"] 80cebff4_efbd_4311_85e9_de0dc81a7eee["base.py"] bd94b6bb_a9a9_4c3a_20e5_3bb8b57e2eaf -->|defined in| 80cebff4_efbd_4311_85e9_de0dc81a7eee 967c88a4_f24b_828c_a121_3b72c0a58b0b["get_all_basemodel_annotations()"] 967c88a4_f24b_828c_a121_3b72c0a58b0b -->|calls| bd94b6bb_a9a9_4c3a_20e5_3bb8b57e2eaf style bd94b6bb_a9a9_4c3a_20e5_3bb8b57e2eaf fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/tools/base.py lines 1540–1569
def _replace_type_vars(
type_: type | TypeVar,
generic_map: dict[TypeVar, type] | None = None,
*,
default_to_bound: bool = True,
) -> type | TypeVar:
"""Replace `TypeVar`s in a type annotation with concrete types.
Args:
type_: The type annotation to process.
generic_map: Mapping of `TypeVar`s to concrete types.
default_to_bound: Whether to use `TypeVar` bounds as defaults.
Returns:
The type with `TypeVar`s replaced.
"""
generic_map = generic_map or {}
if isinstance(type_, TypeVar):
if type_ in generic_map:
return generic_map[type_]
if default_to_bound:
return type_.__bound__ if type_.__bound__ is not None else Any
return type_
if (origin := get_origin(type_)) and (args := get_args(type_)):
new_args = tuple(
_replace_type_vars(arg, generic_map, default_to_bound=default_to_bound)
for arg in args
)
return cast("type", _py_38_safe_origin(origin)[new_args]) # type: ignore[index]
return type_
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does _replace_type_vars() do?
_replace_type_vars() is a function in the langchain codebase, defined in libs/core/langchain_core/tools/base.py.
Where is _replace_type_vars() defined?
_replace_type_vars() is defined in libs/core/langchain_core/tools/base.py at line 1540.
What calls _replace_type_vars()?
_replace_type_vars() is called by 1 function(s): get_all_basemodel_annotations.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free