IsLocalDict Class — langchain Architecture
Architecture documentation for the IsLocalDict class in utils.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD bf16537a_3211_0c4e_b5e4_607d4a0bafb2["IsLocalDict"] ca66092c_447c_d201_0d3c_cfa6ca2cc9d3["utils.py"] bf16537a_3211_0c4e_b5e4_607d4a0bafb2 -->|defined in| ca66092c_447c_d201_0d3c_cfa6ca2cc9d3 2395a235_1daa_5790_341c_73bd8613444f["__init__()"] bf16537a_3211_0c4e_b5e4_607d4a0bafb2 -->|method| 2395a235_1daa_5790_341c_73bd8613444f 7431292a_23e8_37cf_fcb4_2dd29788b135["visit_Subscript()"] bf16537a_3211_0c4e_b5e4_607d4a0bafb2 -->|method| 7431292a_23e8_37cf_fcb4_2dd29788b135 e4145a88_0e13_b701_6e5e_d650adaa4193["visit_Call()"] bf16537a_3211_0c4e_b5e4_607d4a0bafb2 -->|method| e4145a88_0e13_b701_6e5e_d650adaa4193
Relationship Graph
Source Code
libs/core/langchain_core/runnables/utils.py lines 158–205
class IsLocalDict(ast.NodeVisitor):
"""Check if a name is a local dict."""
def __init__(self, name: str, keys: set[str]) -> None:
"""Initialize the visitor.
Args:
name: The name to check.
keys: The keys to populate.
"""
self.name = name
self.keys = keys
@override
def visit_Subscript(self, node: ast.Subscript) -> None:
"""Visit a subscript node.
Args:
node: The node to visit.
"""
if (
isinstance(node.ctx, ast.Load)
and isinstance(node.value, ast.Name)
and node.value.id == self.name
and isinstance(node.slice, ast.Constant)
and isinstance(node.slice.value, str)
):
# we've found a subscript access on the name we're looking for
self.keys.add(node.slice.value)
@override
def visit_Call(self, node: ast.Call) -> None:
"""Visit a call node.
Args:
node: The node to visit.
"""
if (
isinstance(node.func, ast.Attribute)
and isinstance(node.func.value, ast.Name)
and node.func.value.id == self.name
and node.func.attr == "get"
and len(node.args) in {1, 2}
and isinstance(node.args[0], ast.Constant)
and isinstance(node.args[0].value, str)
):
# we've found a .get() call on the name we're looking for
self.keys.add(node.args[0].value)
Defined In
Source
Frequently Asked Questions
What is the IsLocalDict class?
IsLocalDict is a class in the langchain codebase, defined in libs/core/langchain_core/runnables/utils.py.
Where is IsLocalDict defined?
IsLocalDict is defined in libs/core/langchain_core/runnables/utils.py at line 158.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free