Skip to content

docs(toolbox-core): Improve docstrings for context manager functions in sync client and auth module #309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/toolbox-core/src/toolbox_core/auth_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
from toolbox_core import auth_methods

auth_token_provider = auth_methods.aget_google_id_token
toolbox = ToolboxClient(
async with ToolboxClient(
URL,
client_headers={"Authorization": auth_token_provider},
)
tools = await toolbox.load_toolset()
) as toolbox:
tools = await toolbox.load_toolset()
"""

from datetime import datetime, timedelta, timezone
Expand Down
17 changes: 15 additions & 2 deletions packages/toolbox-core/src/toolbox_core/sync_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,22 @@ def add_headers(
self.__async_client.add_headers(headers)

def __enter__(self):
"""Enter the runtime context related to this client instance."""
"""
Enter the runtime context related to this client instance.

Allows the client to be used as a context manager
(e.g., `with ToolboxSyncClient(...) as client:`).

Returns:
self: The client instance itself.
"""
return self

def __exit__(self, exc_type, exc_val, exc_tb):
"""Exit the runtime context and close the client session."""
"""
Exit the runtime context and close the internally managed session.

Allows the client to be used as a context manager
(e.g., `with ToolboxSyncClient(...) as client:`).
"""
self.close()