Skip to content

Commit

Permalink
core: Add support for calls in get_function_nonlocals
Browse files Browse the repository at this point in the history
  • Loading branch information
nfcampos committed Jan 16, 2025
1 parent 667d2a5 commit 13347e1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions libs/core/langchain_core/runnables/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,20 @@ def visit_Attribute(self, node: ast.Attribute) -> Any:
if isinstance(parent, ast.Name):
self.loads.add(parent.id + "." + attr_expr)
self.loads.discard(parent.id)
elif isinstance(parent, ast.Call):
if isinstance(parent.func, ast.Name):
self.loads.add(parent.func.id)
else:
parent = parent.func
attr_expr = ""
while isinstance(parent, ast.Attribute):
if attr_expr:
attr_expr = parent.attr + "." + attr_expr
else:
attr_expr = parent.attr
parent = parent.value
if isinstance(parent, ast.Name):
self.loads.add(parent.id + "." + attr_expr)


class FunctionNonLocals(ast.NodeVisitor):
Expand Down

0 comments on commit 13347e1

Please sign in to comment.