Skip to content

Commit

Permalink
Custom setattr
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw committed Sep 24, 2024
1 parent 1997e25 commit e9de577
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions python/langsmith/run_trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ def _client(self) -> Optional[Client]:
# For backwards compat
return self.ls_client

def __setattr__(self, name, value):
"""Set the _client specially."""
# For backwards compat
if name == "_client":
self.ls_client = value
else:
return super().__setattr__(name, value)

def add_tags(self, tags: Union[Sequence[str], str]) -> None:
"""Add tags to the run."""
if isinstance(tags, str):
Expand Down
6 changes: 5 additions & 1 deletion python/tests/unit_tests/test_run_trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ def test_run_tree_accepts_tpe() -> None:
def test_lazy_rt() -> None:
run_tree = RunTree(name="foo")
assert run_tree.ls_client is None
assert run_tree._client is None
assert isinstance(run_tree.client, Client)
client = Client()
client = Client(api_key="foo")
run_tree._client = client
assert run_tree._client == client

assert RunTree(name="foo", client=client).client == client
assert RunTree(name="foo", ls_client=client).client == client

Expand Down

0 comments on commit e9de577

Please sign in to comment.