Skip to content

[Storage] Decoupled Client Context Manager Methods from Base Client #41442

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

weirongw23-msft
Copy link
Member

No description provided.

@github-actions github-actions bot added the Storage Storage Service (Queues, Blobs, Files) label Jun 5, 2025
@weirongw23-msft
Copy link
Member Author

/azp run python - pullrequest

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@weirongw23-msft
Copy link
Member Author

Placed context managers directly after constructors, removed those implementations from base client (sync / async)

Copy link

github-actions bot commented Jun 6, 2025

API Change Check

APIView identified API level changes in this PR and created the following API reviews

azure-storage-blob
azure-storage-file-datalake
azure-storage-queue
azure-storage-file-share

@weirongw23-msft weirongw23-msft marked this pull request as ready for review June 6, 2025 19:58
@Copilot Copilot AI review requested due to automatic review settings June 6, 2025 19:58
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request decouples context manager methods from the base client into individual client implementations. The key changes include adding enter, exit, and close methods to various synchronous and asynchronous client classes, and removing these context manager methods from shared base classes.

Reviewed Changes

Copilot reviewed 32 out of 32 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_service_client.py Added sync context manager methods (enter, exit, close)
sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_client.py Added sync context manager methods with pylint disable comment for too-many-public-methods
sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client.py Added sync context manager methods
sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client.py Added sync context manager methods
sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/* Added async context manager methods and adjusted generated client building
sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/* Removed context manager methods from shared base classes
sdk/storage/azure-storage-blob/azure/storage/blob/aio/* Added async context manager methods
sdk/storage/azure-storage-blob/azure/storage/blob/* Added sync context manager methods

It need not be used when using with a context manager.

:return: None
:rtype: None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be consistent with the docs between sync/async? Here we document the return type, in sync we don't. We probably don't need to too IMO but it's up to you.

@@ -126,13 +126,13 @@ def __init__(
self._loop = kwargs.get('loop', None)

async def __aenter__(self) -> Self:
await super(DataLakeServiceClient, self).__aenter__()
await self._client.__aenter__()
await self._blob_service_client.__aenter__()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm this is the only place we call enter/aenter on a internal blob client like this. I don't think we need to do that. Calling close on exit should be enough.

@@ -190,6 +190,19 @@ def __init__(
self._client._config.version = get_api_version(kwargs) # type: ignore [assignment]
self._configure_encryption(kwargs)

def __enter__(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's at least document the type for enter since that is an important one. Probably just -> Self? This applies to the whole review.

For exit, maybe we add the return type -> None but leave the *args empty to be filled in in the pyi files.

@@ -120,6 +120,19 @@ def __init__(
self._client._config.version = get_api_version(api_version) # type: ignore [assignment]
self._configure_encryption(kwargs)

def __enter__(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Queue doesn't have pyi files so I guess we need to document the full type for enter/exit here. Reminder this is the full proper type hint for exit:
https://github.com/python/typeshed/blob/567b488fc28978642bfeb70b29f11453b0ff124c/stdlib/imp.pyi#L48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants