Skip to content

Commit 367a7b8

Browse files
authored
docs(toolbox-core): Improve docstrings for context manager functions in sync client and auth module (#309)
* docs(toolbox-core): Improve docstrings for context manager functions in sync client. * docs(toolbox-core): Update auth module docstring to guide using context manager.
1 parent bf4bed3 commit 367a7b8

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

packages/toolbox-core/src/toolbox_core/auth_methods.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
from toolbox_core import auth_methods
2121
2222
auth_token_provider = auth_methods.aget_google_id_token
23-
toolbox = ToolboxClient(
23+
async with ToolboxClient(
2424
URL,
2525
client_headers={"Authorization": auth_token_provider},
26-
)
27-
tools = await toolbox.load_toolset()
26+
) as toolbox:
27+
tools = await toolbox.load_toolset()
2828
"""
2929

3030
from datetime import datetime, timedelta, timezone

packages/toolbox-core/src/toolbox_core/sync_client.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,22 @@ def add_headers(
176176
self.__async_client.add_headers(headers)
177177

178178
def __enter__(self):
179-
"""Enter the runtime context related to this client instance."""
179+
"""
180+
Enter the runtime context related to this client instance.
181+
182+
Allows the client to be used as a context manager
183+
(e.g., `with ToolboxSyncClient(...) as client:`).
184+
185+
Returns:
186+
self: The client instance itself.
187+
"""
180188
return self
181189

182190
def __exit__(self, exc_type, exc_val, exc_tb):
183-
"""Exit the runtime context and close the client session."""
191+
"""
192+
Exit the runtime context and close the internally managed session.
193+
194+
Allows the client to be used as a context manager
195+
(e.g., `with ToolboxSyncClient(...) as client:`).
196+
"""
184197
self.close()

0 commit comments

Comments
 (0)