From 74e4af9c05250072eb1b333b010a6d177c620b1a Mon Sep 17 00:00:00 2001 From: Jacob Lauzon Date: Fri, 19 Aug 2022 15:38:11 -0700 Subject: [PATCH 1/2] Update batch type hinting --- .../azure/storage/blob/_container_client.py | 54 +++++++++---------- .../blob/aio/_container_client_async.py | 36 ++++++------- 2 files changed, 43 insertions(+), 47 deletions(-) diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py index 39df3da26e2d..86c797989a45 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py @@ -1017,7 +1017,7 @@ def delete_blob( and retains the blob or snapshot for specified number of days. After specified number of days, blob's data is removed from the service during garbage collection. Soft deleted blob or snapshot is accessible through :func:`list_blobs()` specifying `include=["deleted"]` - option. Soft-deleted blob or snapshot can be restored using :func:`~BlobClient.undelete()` + option. Soft-deleted blob or snapshot can be restored using :func:`~azure.storage.blob.BlobClient.undelete()` :param blob: The blob with which to interact. If specified, this value will override a blob value specified in the blob URL. @@ -1252,10 +1252,10 @@ def _generate_delete_blobs_subrequest_options( return query_parameters, header_parameters - def _generate_delete_blobs_options(self, - *blobs, # type: List[Union[str, BlobProperties, dict]] - **kwargs - ): + def _generate_delete_blobs_options( + self, *blobs: Union[str, Dict[str, Any], BlobProperties], + **kwargs: Any + ): timeout = kwargs.pop('timeout', None) raise_on_any_failure = kwargs.pop('raise_on_any_failure', True) delete_snapshots = kwargs.pop('delete_snapshots', None) @@ -1309,8 +1309,10 @@ def _generate_delete_blobs_options(self, return reqs, kwargs @distributed_trace - def delete_blobs(self, *blobs, **kwargs): - # type: (...) -> Iterator[HttpResponse] + def delete_blobs( + self, *blobs: Union[str, Dict[str, Any], BlobProperties], + **kwargs: Any + ) -> Iterator[HttpResponse]: """Marks the specified blobs or snapshots for deletion. The blobs are later deleted during garbage collection. @@ -1321,7 +1323,7 @@ def delete_blobs(self, *blobs, **kwargs): and retains the blobs or snapshots for specified number of days. After specified number of days, blobs' data is removed from the service during garbage collection. Soft deleted blobs or snapshots are accessible through :func:`list_blobs()` specifying `include=["deleted"]` - Soft-deleted blobs or snapshots can be restored using :func:`~BlobClient.undelete()` + Soft-deleted blobs or snapshots can be restored using :func:`~azure.storage.blob.BlobClient.undelete()` The maximum number of blobs that can be deleted in a single request is 256. @@ -1353,7 +1355,7 @@ def delete_blobs(self, *blobs, **kwargs): timeout for subrequest: key: 'timeout', value type: int - :type blobs: list[str], list[dict], or list[~azure.storage.blob.BlobProperties] + :type blobs: str or dict(str, Any) or ~azure.storage.blob.BlobProperties :keyword str delete_snapshots: Required if a blob has associated snapshots. Values include: - "only": Deletes only the blobs snapshots. @@ -1442,11 +1444,11 @@ def _generate_set_tiers_subrequest_options( return query_parameters, header_parameters - def _generate_set_tiers_options(self, - blob_tier, # type: Optional[Union[str, StandardBlobTier, PremiumPageBlobTier]] - *blobs, # type: List[Union[str, BlobProperties, dict]] - **kwargs - ): + def _generate_set_tiers_options( + self, blob_tier: Optional[Union[str, StandardBlobTier]], + *blobs: Union[str, Dict[str, Any], BlobProperties], + **kwargs: Any + ): timeout = kwargs.pop('timeout', None) raise_on_any_failure = kwargs.pop('raise_on_any_failure', True) rehydrate_priority = kwargs.pop('rehydrate_priority', None) @@ -1490,12 +1492,10 @@ def _generate_set_tiers_options(self, @distributed_trace def set_standard_blob_tier_blobs( - self, - standard_blob_tier, # type: Optional[Union[str, StandardBlobTier]] - *blobs, # type: List[Union[str, BlobProperties, dict]] - **kwargs - ): - # type: (...) -> Iterator[HttpResponse] + self, standard_blob_tier: Optional[Union[str, StandardBlobTier]], + *blobs: Union[str, Dict[str, Any], BlobProperties], + **kwargs: Any + ) -> Iterator[HttpResponse]: """This operation sets the tier on block blobs. A block blob's tier determines Hot/Cool/Archive storage type. @@ -1540,7 +1540,7 @@ def set_standard_blob_tier_blobs( timeout for subrequest: key: 'timeout', value type: int - :type blobs: list[str], list[dict], or list[~azure.storage.blob.BlobProperties] + :type blobs: str or dict(str, Any) or ~azure.storage.blob.BlobProperties :keyword ~azure.storage.blob.RehydratePriority rehydrate_priority: Indicates the priority with which to rehydrate an archived blob :keyword str if_tags_match_condition: @@ -1563,12 +1563,10 @@ def set_standard_blob_tier_blobs( @distributed_trace def set_premium_page_blob_tier_blobs( - self, - premium_page_blob_tier, # type: Optional[Union[str, PremiumPageBlobTier]] - *blobs, # type: List[Union[str, BlobProperties, dict]] - **kwargs - ): - # type: (...) -> Iterator[HttpResponse] + self, premium_page_blob_tier: Optional[Union[str, PremiumPageBlobTier]], + *blobs: Union[str, Dict[str, Any], BlobProperties], + **kwargs: Any + ) -> Iterator[HttpResponse]: """Sets the page blob tiers on all blobs. This API is only supported for page blobs on premium accounts. The maximum number of blobs that can be updated in a single request is 256. @@ -1599,7 +1597,7 @@ def set_premium_page_blob_tier_blobs( timeout for subrequest: key: 'timeout', value type: int - :type blobs: list[str], list[dict], or list[~azure.storage.blob.BlobProperties] + :type blobs: str or dict(str, Any) or ~azure.storage.blob.BlobProperties :keyword int timeout: The timeout parameter is expressed in seconds. This method may make multiple calls to the Azure service and the timeout will apply to diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py index a139e3f4bf3e..572cb5379f36 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py @@ -875,8 +875,8 @@ async def delete_blob( If a delete retention policy is enabled for the service, then this operation soft deletes the blob or snapshot and retains the blob or snapshot for specified number of days. After specified number of days, blob's data is removed from the service during garbage collection. - Soft deleted blob or snapshot is accessible through :func:`list_blobs()` specifying `include=["deleted"]` - option. Soft-deleted blob or snapshot can be restored using :func:`~BlobClient.undelete()` + Soft deleted blobs or snapshots are accessible through :func:`list_blobs()` specifying `include=["deleted"]` + Soft-deleted blob or snapshot can be restored using :func:`~azure.storage.blob.aio.BlobClient.undelete()` :param blob: The blob with which to interact. If specified, this value will override a blob value specified in the blob URL. @@ -1046,9 +1046,9 @@ async def download_blob( **kwargs) @distributed_trace_async - async def delete_blobs( # pylint: disable=arguments-differ - self, *blobs: List[Union[str, BlobProperties, dict]], - **kwargs + async def delete_blobs( + self, *blobs: Union[str, Dict[str, Any], BlobProperties], + **kwargs: Any ) -> AsyncIterator[AsyncHttpResponse]: """Marks the specified blobs or snapshots for deletion. @@ -1060,7 +1060,7 @@ async def delete_blobs( # pylint: disable=arguments-differ and retains the blobs or snapshots for specified number of days. After specified number of days, blobs' data is removed from the service during garbage collection. Soft deleted blobs or snapshots are accessible through :func:`list_blobs()` specifying `include=["deleted"]` - Soft-deleted blobs or snapshots can be restored using :func:`~BlobClient.undelete()` + Soft-deleted blobs or snapshots can be restored using :func:`~azure.storage.blob.aio.BlobClient.undelete()` The maximum number of blobs that can be deleted in a single request is 256. @@ -1090,7 +1090,7 @@ async def delete_blobs( # pylint: disable=arguments-differ timeout for subrequest: key: 'timeout', value type: int - :type blobs: list[str], list[dict], or list[~azure.storage.blob.BlobProperties] + :type blobs: str or dict(str, Any) or ~azure.storage.blob.BlobProperties :keyword str delete_snapshots: Required if a blob has associated snapshots. Values include: - "only": Deletes only the blobs snapshots. @@ -1138,12 +1138,11 @@ async def delete_blobs( # pylint: disable=arguments-differ return await self._batch_send(*reqs, **options) - @distributed_trace + @distributed_trace_async async def set_standard_blob_tier_blobs( - self, - standard_blob_tier: Union[str, 'StandardBlobTier'], - *blobs: List[Union[str, BlobProperties, dict]], - **kwargs + self, standard_blob_tier: Union[str, 'StandardBlobTier'], + *blobs: Union[str, Dict[str, Any], BlobProperties], + **kwargs: Any ) -> AsyncIterator[AsyncHttpResponse]: """This operation sets the tier on block blobs. @@ -1184,7 +1183,7 @@ async def set_standard_blob_tier_blobs( timeout for subrequest: key: 'timeout', value type: int - :type blobs: list[str], list[dict], or list[~azure.storage.blob.BlobProperties] + :type blobs: str or dict(str, Any) or ~azure.storage.blob.BlobProperties :keyword ~azure.storage.blob.RehydratePriority rehydrate_priority: Indicates the priority with which to rehydrate an archived blob :keyword str if_tags_match_condition: @@ -1206,12 +1205,11 @@ async def set_standard_blob_tier_blobs( return await self._batch_send(*reqs, **options) - @distributed_trace + @distributed_trace_async async def set_premium_page_blob_tier_blobs( - self, - premium_page_blob_tier: Union[str, 'PremiumPageBlobTier'], - *blobs: List[Union[str, BlobProperties, dict]], - **kwargs + self, premium_page_blob_tier: Union[str, 'PremiumPageBlobTier'], + *blobs: Union[str, Dict[str, Any], BlobProperties], + **kwargs: Any ) -> AsyncIterator[AsyncHttpResponse]: """Sets the page blob tiers on the blobs. This API is only supported for page blobs on premium accounts. @@ -1242,7 +1240,7 @@ async def set_premium_page_blob_tier_blobs( timeout for subrequest: key: 'timeout', value type: int - :type blobs: list[str], list[dict], or list[~azure.storage.blob.BlobProperties] + :type blobs: str or dict(str, Any) or ~azure.storage.blob.BlobProperties :keyword int timeout: The timeout parameter is expressed in seconds. This method may make multiple calls to the Azure service and the timeout will apply to From d8edc434fe78ed481cf7515a70c91430a29a2f83 Mon Sep 17 00:00:00 2001 From: Jacob Lauzon Date: Fri, 19 Aug 2022 16:57:01 -0700 Subject: [PATCH 2/2] Fix build/lint --- .../azure/storage/blob/_container_client.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py index 86c797989a45..809cf50866ab 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py @@ -17,7 +17,7 @@ from azure.core.exceptions import HttpResponseError, ResourceNotFoundError from azure.core.paging import ItemPaged from azure.core.pipeline import Pipeline -from azure.core.pipeline.transport import HttpRequest +from azure.core.pipeline.transport import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from ._shared.base_client import StorageAccountHostsMixin, TransportWrapper, parse_connection_str, parse_query @@ -44,7 +44,6 @@ from ._serialize import get_modify_conditions, get_container_cpk_scope_info, get_api_version, get_access_conditions if TYPE_CHECKING: - from azure.core.pipeline.transport import HttpResponse # pylint: disable=ungrouped-imports from datetime import datetime from ._models import ( # pylint: disable=unused-import PublicAccess, @@ -1445,7 +1444,7 @@ def _generate_set_tiers_subrequest_options( return query_parameters, header_parameters def _generate_set_tiers_options( - self, blob_tier: Optional[Union[str, StandardBlobTier]], + self, blob_tier: Optional[Union[str, 'StandardBlobTier', 'PremiumPageBlobTier']], *blobs: Union[str, Dict[str, Any], BlobProperties], **kwargs: Any ): @@ -1492,7 +1491,7 @@ def _generate_set_tiers_options( @distributed_trace def set_standard_blob_tier_blobs( - self, standard_blob_tier: Optional[Union[str, StandardBlobTier]], + self, standard_blob_tier: Optional[Union[str, 'StandardBlobTier']], *blobs: Union[str, Dict[str, Any], BlobProperties], **kwargs: Any ) -> Iterator[HttpResponse]: @@ -1563,7 +1562,7 @@ def set_standard_blob_tier_blobs( @distributed_trace def set_premium_page_blob_tier_blobs( - self, premium_page_blob_tier: Optional[Union[str, PremiumPageBlobTier]], + self, premium_page_blob_tier: Optional[Union[str, 'PremiumPageBlobTier']], *blobs: Union[str, Dict[str, Any], BlobProperties], **kwargs: Any ) -> Iterator[HttpResponse]: