From f1ab82da02cd0b1c763802a23e393af18cecc37f Mon Sep 17 00:00:00 2001 From: Jacob Lauzon Date: Mon, 10 Oct 2022 16:49:11 -0700 Subject: [PATCH 1/5] Adjust type hints for init and classmethods for file-share --- .../storage/fileshare/_directory_client.py | 58 ++++++++---------- .../azure/storage/fileshare/_file_client.py | 61 ++++++++----------- .../azure/storage/fileshare/_share_client.py | 53 ++++++++-------- .../fileshare/_share_service_client.py | 30 ++++----- .../fileshare/aio/_directory_client_async.py | 23 ++++--- .../fileshare/aio/_file_client_async.py | 27 ++++---- .../fileshare/aio/_share_client_async.py | 16 ++--- .../aio/_share_service_client_async.py | 19 +++--- 8 files changed, 129 insertions(+), 158 deletions(-) diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client.py index 3c4132a59512..6bfcea0519ee 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client.py @@ -6,23 +6,18 @@ import functools import time -from typing import ( # pylint: disable=unused-import +from typing import ( Optional, Union, Any, Dict, TYPE_CHECKING ) - - -try: - from urllib.parse import urlparse, quote, unquote -except ImportError: - from urlparse import urlparse # type: ignore - from urllib2 import quote, unquote # type: ignore +from urllib.parse import urlparse, quote, unquote import six +from typing_extensions import Self + from azure.core.exceptions import HttpResponseError, ResourceNotFoundError from azure.core.paging import ItemPaged from azure.core.pipeline import Pipeline from azure.core.tracing.decorator import distributed_trace - from ._generated import AzureFileStorage from ._shared.base_client import StorageAccountHostsMixin, TransportWrapper, parse_connection_str, parse_query from ._shared.request_handlers import add_metadata_headers @@ -35,8 +30,9 @@ from ._models import DirectoryPropertiesPaged, HandlesPaged, NTFSAttributes # pylint: disable=unused-import if TYPE_CHECKING: + from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential from datetime import datetime - from ._models import ShareProperties, DirectoryProperties, ContentSettings + from ._models import DirectoryProperties from ._generated.models import HandleItem @@ -81,15 +77,14 @@ class ShareDirectoryClient(StorageAccountHostsMixin): The hostname of the secondary endpoint. :keyword int max_range_size: The maximum range size used for a file upload. Defaults to 4*1024*1024. """ - def __init__( # type: ignore - self, account_url, # type: str - share_name, # type: str - directory_path, # type: str - snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Optional[Any] - ): - # type: (...) -> None + def __init__( + self, account_url: str, + share_name: str, + directory_path: str, + snapshot: Optional[Union[str, Dict[str, Any]]] = None, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> None: try: if not account_url.lower().startswith('http'): account_url = "https://" + account_url @@ -125,12 +120,12 @@ def __init__( # type: ignore self._client._config.version = get_api_version(kwargs) # pylint: disable=protected-access @classmethod - def from_directory_url(cls, directory_url, # type: str - snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Optional[Any] - ): - # type: (...) -> ShareDirectoryClient + def from_directory_url( + cls, directory_url: str, + snapshot: Optional[Union[str, Dict[str, Any]]] = None, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> Self: """Create a ShareDirectoryClient from a directory url. :param str directory_url: @@ -190,13 +185,12 @@ def _format_url(self, hostname): @classmethod def from_connection_string( - cls, conn_str, # type: str - share_name, # type: str - directory_path, # type: str - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Any - ): - # type: (...) -> ShareDirectoryClient + cls, conn_str: str, + share_name: str, + directory_path: str, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> Self: """Create ShareDirectoryClient from a Connection String. :param str conn_str: diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client.py index c3d3afdd461f..d33e54840f8c 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client.py @@ -7,23 +7,18 @@ import functools import time from io import BytesIO -from typing import ( # pylint: disable=unused-import - Optional, Union, IO, List, Dict, Any, Iterable, Tuple, +from typing import ( + Optional, Union, List, Dict, Any, Tuple, TYPE_CHECKING ) - - -try: - from urllib.parse import urlparse, quote, unquote -except ImportError: - from urlparse import urlparse # type: ignore - from urllib2 import quote, unquote # type: ignore +from urllib.parse import urlparse, quote, unquote import six +from typing_extensions import Self + from azure.core.exceptions import HttpResponseError from azure.core.paging import ItemPaged # pylint: disable=ungrouped-imports from azure.core.tracing.decorator import distributed_trace - from ._generated import AzureFileStorage from ._generated.models import FileHTTPHeaders from ._shared.uploads import IterStreamer, FileChunkUploader, upload_data_chunks @@ -46,8 +41,9 @@ from ._download import StorageStreamDownloader if TYPE_CHECKING: + from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential from datetime import datetime - from ._models import ShareProperties, ContentSettings, FileProperties, Handle + from ._models import ContentSettings, FileProperties, Handle from ._generated.models import HandleItem @@ -141,15 +137,14 @@ class ShareFileClient(StorageAccountHostsMixin): The hostname of the secondary endpoint. :keyword int max_range_size: The maximum range size used for a file upload. Defaults to 4*1024*1024. """ - def __init__( # type: ignore - self, account_url, # type: str - share_name, # type: str - file_path, # type: str - snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Any - ): - # type: (...) -> None + def __init__( + self, account_url: str, + share_name: str, + file_path: str, + snapshot: Optional[Union[str, Dict[str, Any]]] = None, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> None: try: if not account_url.lower().startswith('http'): account_url = "https://" + account_url @@ -189,12 +184,11 @@ def __init__( # type: ignore @classmethod def from_file_url( - cls, file_url, # type: str - snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Any - ): - # type: (...) -> ShareFileClient + cls, file_url: str, # type: str + snapshot: Optional[Union[str, Dict[str, Any]]] = None, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> Self: """A client to interact with a specific file, although that file may not yet exist. :param str file_url: The full URI to the file. @@ -247,14 +241,13 @@ def _format_url(self, hostname): @classmethod def from_connection_string( - cls, conn_str, # type: str - share_name, # type: str - file_path, # type: str - snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Any - ): - # type: (...) -> ShareFileClient + cls, conn_str: str, + share_name: str, + file_path: str, + snapshot: Optional[Union[str, Dict[str, Any]]] = None, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> Self: """Create ShareFileClient from a Connection String. :param str conn_str: diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_client.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_client.py index 6207e2115cd3..09513b41aede 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_client.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_client.py @@ -4,18 +4,14 @@ # license information. # -------------------------------------------------------------------------- -from typing import ( # pylint: disable=unused-import +from typing import ( Optional, Union, Dict, Any, Iterable, TYPE_CHECKING ) - - -try: - from urllib.parse import urlparse, quote, unquote -except ImportError: - from urlparse import urlparse # type: ignore - from urllib2 import quote, unquote # type: ignore +from urllib.parse import urlparse, quote, unquote import six +from typing_extensions import Self + from azure.core.exceptions import HttpResponseError from azure.core.tracing.decorator import distributed_trace from azure.core.pipeline import Pipeline @@ -39,6 +35,7 @@ if TYPE_CHECKING: + from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential from ._models import ShareProperties, AccessPolicy @@ -80,14 +77,13 @@ class ShareClient(StorageAccountHostsMixin): # pylint: disable=too-many-public-m The hostname of the secondary endpoint. :keyword int max_range_size: The maximum range size used for a file upload. Defaults to 4*1024*1024. """ - def __init__( # type: ignore - self, account_url, # type: str - share_name, # type: str - snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Any - ): - # type: (...) -> None + def __init__( + self, account_url: str, + share_name: str, + snapshot: Optional[Union[str, Dict[str, Any]]] = None, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> None: try: if not account_url.lower().startswith('http'): account_url = "https://" + account_url @@ -122,12 +118,12 @@ def __init__( # type: ignore self._client._config.version = get_api_version(kwargs) # pylint: disable=protected-access @classmethod - def from_share_url(cls, share_url, # type: str - snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Any - ): - # type: (...) -> ShareClient + def from_share_url( + cls, share_url: str, + snapshot: Optional[Union[str, Dict[str, Any]]] = None, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> Self: """ :param str share_url: The full URI to the share. :param str snapshot: @@ -194,13 +190,12 @@ def _format_url(self, hostname): @classmethod def from_connection_string( - cls, conn_str, # type: str - share_name, # type: str - snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Any - ): - # type: (...) -> ShareClient + cls, conn_str: str, + share_name: str, + snapshot: Optional[Union[str, Dict[str, Any]]] = None, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> Self: """Create ShareClient from a Connection String. :param str conn_str: diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_service_client.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_service_client.py index da9c8a065957..3ffa5522e243 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_service_client.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_service_client.py @@ -5,16 +5,13 @@ # -------------------------------------------------------------------------- import functools -from typing import ( # pylint: disable=unused-import +from typing import ( Union, Optional, Any, Dict, List, TYPE_CHECKING ) +from urllib.parse import urlparse - -try: - from urllib.parse import urlparse -except ImportError: - from urlparse import urlparse # type: ignore +from typing_extensions import Self from azure.core.exceptions import HttpResponseError from azure.core.paging import ItemPaged @@ -32,7 +29,7 @@ ) if TYPE_CHECKING: - from datetime import datetime + from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential from ._models import ( ShareProperties, Metrics, @@ -86,11 +83,10 @@ class ShareServiceClient(StorageAccountHostsMixin): :caption: Create the share service client with url and credential. """ def __init__( - self, account_url, # type: str - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Any - ): - # type: (...) -> None + self, account_url: str, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> None: try: if not account_url.lower().startswith('http'): account_url = "https://" + account_url @@ -119,10 +115,10 @@ def _format_url(self, hostname): @classmethod def from_connection_string( - cls, conn_str, # type: str - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Any - ): # type: (...) -> ShareServiceClient + cls, conn_str: str, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> Self: """Create ShareServiceClient from a Connection String. :param str conn_str: @@ -186,7 +182,7 @@ def set_service_properties( self, hour_metrics=None, # type: Optional[Metrics] minute_metrics=None, # type: Optional[Metrics] cors=None, # type: Optional[List[CorsRule]] - protocol=None, # type: Optional[ShareProtocolSettings], + protocol=None, # type: Optional[ShareProtocolSettings] **kwargs ): # type: (...) -> None diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_directory_client_async.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_directory_client_async.py index 8ff85fa6a3a0..a8b35ad95438 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_directory_client_async.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_directory_client_async.py @@ -8,7 +8,7 @@ import sys import time import warnings -from typing import ( # pylint: disable=unused-import +from typing import ( Optional, Union, Any, Dict, TYPE_CHECKING ) @@ -19,7 +19,6 @@ from azure.core.tracing.decorator_async import distributed_trace_async from .._parser import _get_file_permission, _datetime_to_str from .._shared.parser import _str - from .._generated.aio import AzureFileStorage from .._shared.base_client_async import AsyncStorageAccountHostsMixin, AsyncTransportWrapper from .._shared.policies_async import ExponentialRetry @@ -32,8 +31,9 @@ from ._models import DirectoryPropertiesPaged, HandlesPaged if TYPE_CHECKING: + from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential from datetime import datetime - from .._models import ShareProperties, DirectoryProperties, ContentSettings, NTFSAttributes + from .._models import DirectoryProperties, NTFSAttributes from .._generated.models import HandleItem @@ -74,15 +74,14 @@ class ShareDirectoryClient(AsyncStorageAccountHostsMixin, ShareDirectoryClientBa The hostname of the secondary endpoint. :keyword int max_range_size: The maximum range size used for a file upload. Defaults to 4*1024*1024. """ - def __init__( # type: ignore - self, account_url, # type: str - share_name, # type: str - directory_path, # type: str - snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Optional[Any] - ): - # type: (...) -> None + def __init__( + self, account_url: str, + share_name: str, + directory_path: str, + snapshot: Optional[Union[str, Dict[str, Any]]] = None, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> None: kwargs['retry_policy'] = kwargs.get('retry_policy') or ExponentialRetry(**kwargs) loop = kwargs.pop('loop', None) if loop and sys.version_info >= (3, 8): diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_file_client_async.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_file_client_async.py index 9784c35999c4..52fd5b3797e9 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_file_client_async.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_file_client_async.py @@ -9,17 +9,16 @@ import time import warnings from io import BytesIO -from typing import Optional, Union, IO, List, Tuple, Dict, Any, Iterable, TYPE_CHECKING # pylint: disable=unused-import +from typing import Optional, Union, List, Tuple, Dict, Any, TYPE_CHECKING import six + from azure.core.async_paging import AsyncItemPaged from azure.core.exceptions import HttpResponseError - from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from .._parser import _datetime_to_str, _get_file_permission from .._shared.parser import _str - from .._generated.aio import AzureFileStorage from .._generated.models import FileHTTPHeaders from .._shared.policies_async import ExponentialRetry @@ -41,8 +40,9 @@ from ._download_async import StorageStreamDownloader if TYPE_CHECKING: + from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential from datetime import datetime - from .._models import ShareProperties, ContentSettings, FileProperties, NTFSAttributes + from .._models import ContentSettings, FileProperties, NTFSAttributes from .._generated.models import HandleItem @@ -131,17 +131,14 @@ class ShareFileClient(AsyncStorageAccountHostsMixin, ShareFileClientBase): The hostname of the secondary endpoint. :keyword int max_range_size: The maximum range size used for a file upload. Defaults to 4*1024*1024. """ - - def __init__( # type: ignore - self, - account_url, # type: str - share_name, # type: str - file_path, # type: str - snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Any - ): - # type: (...) -> None + def __init__( + self, account_url: str, + share_name: str, + file_path: str, + snapshot: Optional[Union[str, Dict[str, Any]]] = None, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> None: kwargs["retry_policy"] = kwargs.get("retry_policy") or ExponentialRetry(**kwargs) loop = kwargs.pop('loop', None) if loop and sys.version_info >= (3, 8): diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_client_async.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_client_async.py index 1bc82258aea2..c16a9fbe2fd0 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_client_async.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_client_async.py @@ -34,6 +34,7 @@ from .._models import ShareProtocols if TYPE_CHECKING: + from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential from .._models import ShareProperties, AccessPolicy @@ -71,14 +72,13 @@ class ShareClient(AsyncStorageAccountHostsMixin, ShareClientBase): The hostname of the secondary endpoint. :keyword int max_range_size: The maximum range size used for a file upload. Defaults to 4*1024*1024. """ - def __init__( # type: ignore - self, account_url, # type: str - share_name, # type: str - snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Any - ): - # type: (...) -> None + def __init__( + self, account_url: str, + share_name: str, + snapshot: Optional[Union[str, Dict[str, Any]]] = None, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> None: kwargs['retry_policy'] = kwargs.get('retry_policy') or ExponentialRetry(**kwargs) loop = kwargs.pop('loop', None) if loop and sys.version_info >= (3, 8): diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_service_client_async.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_service_client_async.py index 75bdaa37155e..4a008eb40da7 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_service_client_async.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_service_client_async.py @@ -7,8 +7,8 @@ import functools import sys import warnings -from typing import ( # pylint: disable=unused-import - Union, Optional, Any, Iterable, Dict, List, +from typing import ( + Union, Optional, Any, Dict, List, TYPE_CHECKING ) @@ -17,7 +17,6 @@ from azure.core.tracing.decorator import distributed_trace from azure.core.pipeline import AsyncPipeline from azure.core.tracing.decorator_async import distributed_trace_async - from .._shared.base_client_async import AsyncStorageAccountHostsMixin, AsyncTransportWrapper from .._shared.response_handlers import process_storage_error from .._shared.policies_async import ExponentialRetry @@ -30,8 +29,7 @@ from .._models import service_properties_deserialize if TYPE_CHECKING: - from datetime import datetime - from .._shared.models import ResourceTypes, AccountSasPermissions + from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential from .._models import ( ShareProperties, Metrics, @@ -81,11 +79,10 @@ class ShareServiceClient(AsyncStorageAccountHostsMixin, ShareServiceClientBase): :caption: Create the share service client with url and credential. """ def __init__( - self, account_url, # type: str - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Any - ): - # type: (...) -> None + self, account_url: str, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> None: kwargs['retry_policy'] = kwargs.get('retry_policy') or ExponentialRetry(**kwargs) loop = kwargs.pop('loop', None) if loop and sys.version_info >= (3, 8): @@ -131,7 +128,7 @@ async def set_service_properties( self, hour_metrics=None, # type: Optional[Metrics] minute_metrics=None, # type: Optional[Metrics] cors=None, # type: Optional[List[CorsRule]] - protocol=None, # type: Optional[ShareProtocolSettings], + protocol=None, # type: Optional[ShareProtocolSettings] **kwargs ): # type: (...) -> None From 55d02d01fc03081dec6d3d43c357f5484909b43a Mon Sep 17 00:00:00 2001 From: Jacob Lauzon Date: Mon, 10 Oct 2022 17:13:19 -0700 Subject: [PATCH 2/5] Adjust type hints for Queue --- .../azure/storage/queue/_queue_client.py | 39 +++++++++---------- .../storage/queue/_queue_service_client.py | 21 +++++----- .../storage/queue/aio/_queue_client_async.py | 18 ++++----- .../queue/aio/_queue_service_client_async.py | 13 +++---- 4 files changed, 44 insertions(+), 47 deletions(-) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_client.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_client.py index 1fc5ec1ce5c6..b204debd79f8 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_client.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_client.py @@ -7,15 +7,16 @@ import functools import warnings from typing import ( # pylint: disable=unused-import - Any, Dict, List, Optional, + Any, Dict, List, Optional, Union, TYPE_CHECKING) from urllib.parse import urlparse, quote, unquote import six +from typing_extensions import Self + from azure.core.exceptions import HttpResponseError from azure.core.paging import ItemPaged from azure.core.tracing.decorator import distributed_trace - from ._shared.base_client import StorageAccountHostsMixin, parse_connection_str, parse_query from ._shared.request_handlers import add_metadata_headers, serialize_iso from ._shared.response_handlers import ( @@ -31,6 +32,7 @@ from ._serialize import get_api_version if TYPE_CHECKING: + from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential from ._models import QueueProperties @@ -77,12 +79,11 @@ class QueueClient(StorageAccountHostsMixin, StorageEncryptionMixin): :caption: Create the queue client with url and credential. """ def __init__( - self, account_url, # type: str - queue_name, # type: str - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Any - ): - # type: (...) -> None + self, account_url: str, + queue_name: str, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> None: try: if not account_url.lower().startswith('http'): account_url = "https://" + account_url @@ -120,12 +121,11 @@ def _format_url(self, hostname): f"/{quote(queue_name)}{self._query_str}") @classmethod - def from_queue_url(cls, - queue_url, # type: str - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Any - ): - # type: (...) -> QueueClient + def from_queue_url( + cls, queue_url: str, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> Self: """A client to interact with a specific Queue. :param str queue_url: The full URI to the queue, including SAS token if used. @@ -165,12 +165,11 @@ def from_queue_url(cls, @classmethod def from_connection_string( - cls, conn_str, # type: str - queue_name, # type: str - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Any - ): - # type: (...) -> QueueClient + cls, conn_str: str, + queue_name: str, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> Self: """Create QueueClient from a Connection String. :param str conn_str: diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_service_client.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_service_client.py index 78d368687f26..90a50b5f74b5 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_service_client.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_service_client.py @@ -10,11 +10,12 @@ TYPE_CHECKING) from urllib.parse import urlparse +from typing_extensions import Self + from azure.core.exceptions import HttpResponseError from azure.core.paging import ItemPaged from azure.core.pipeline import Pipeline from azure.core.tracing.decorator import distributed_trace - from ._shared.base_client import StorageAccountHostsMixin, TransportWrapper, parse_connection_str, parse_query from ._shared.models import LocationMode from ._shared.response_handlers import process_storage_error @@ -30,6 +31,7 @@ from ._queue_client import QueueClient if TYPE_CHECKING: + from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential from ._models import ( CorsRule, Metrics, @@ -87,11 +89,10 @@ class QueueServiceClient(StorageAccountHostsMixin, StorageEncryptionMixin): """ def __init__( - self, account_url, # type: str - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Any - ): - # type: (...) -> None + self, account_url: str, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> None: try: if not account_url.lower().startswith('http'): account_url = "https://" + account_url @@ -118,10 +119,10 @@ def _format_url(self, hostname): @classmethod def from_connection_string( - cls, conn_str, # type: str - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Any - ): # type: (...) -> QueueServiceClient + cls, conn_str: str, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> Self: """Create QueueServiceClient from a Connection String. :param str conn_str: diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_client_async.py b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_client_async.py index eb0c01017f81..60bff6a2891b 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_client_async.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_client_async.py @@ -7,15 +7,14 @@ import functools import warnings -from typing import ( # pylint: disable=unused-import - Any, Dict, List, Optional, +from typing import ( + Any, Dict, List, Optional, Union, TYPE_CHECKING) from azure.core.async_paging import AsyncItemPaged from azure.core.exceptions import HttpResponseError from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async - from .._serialize import get_api_version from .._shared.base_client_async import AsyncStorageAccountHostsMixin from .._shared.policies_async import ExponentialRetry @@ -34,6 +33,7 @@ from ._models import MessagesPaged if TYPE_CHECKING: + from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential from .._models import QueueProperties @@ -84,13 +84,11 @@ class QueueClient(AsyncStorageAccountHostsMixin, QueueClientBase, StorageEncrypt """ def __init__( - self, - account_url, # type: str - queue_name, # type: str - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Any - ): - # type: (...) -> None + self, account_url: str, + queue_name: str, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> None: kwargs["retry_policy"] = kwargs.get("retry_policy") or ExponentialRetry(**kwargs) loop = kwargs.pop('loop', None) super(QueueClient, self).__init__( diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_service_client_async.py b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_service_client_async.py index 368cee23f26d..423d8ac1c515 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_service_client_async.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_service_client_async.py @@ -6,7 +6,7 @@ # pylint: disable=invalid-overridden-method import functools -from typing import ( # pylint: disable=unused-import +from typing import ( Any, Dict, List, Optional, Union, TYPE_CHECKING) @@ -15,7 +15,6 @@ from azure.core.pipeline import AsyncPipeline from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async - from .._serialize import get_api_version from .._shared.base_client_async import AsyncStorageAccountHostsMixin, AsyncTransportWrapper from .._shared.policies_async import ExponentialRetry @@ -33,6 +32,7 @@ from ._queue_client_async import QueueClient if TYPE_CHECKING: + from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential from .._models import ( CorsRule, Metrics, @@ -86,11 +86,10 @@ class QueueServiceClient(AsyncStorageAccountHostsMixin, QueueServiceClientBase, """ def __init__( - self, account_url, # type: str - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Any - ): - # type: (...) -> None + self, account_url: str, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> None: kwargs['retry_policy'] = kwargs.get('retry_policy') or ExponentialRetry(**kwargs) loop = kwargs.pop('loop', None) super(QueueServiceClient, self).__init__( # type: ignore From c9ab21bc9647261a538341e1b013d7dc290f4c8e Mon Sep 17 00:00:00 2001 From: Jacob Lauzon Date: Mon, 10 Oct 2022 17:20:26 -0700 Subject: [PATCH 3/5] Adjust type hints in ChangeFeed --- .../blob/changefeed/_change_feed_client.py | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/sdk/storage/azure-storage-blob-changefeed/azure/storage/blob/changefeed/_change_feed_client.py b/sdk/storage/azure-storage-blob-changefeed/azure/storage/blob/changefeed/_change_feed_client.py index c91eccc5f53b..f2ecc39d8733 100644 --- a/sdk/storage/azure-storage-blob-changefeed/azure/storage/blob/changefeed/_change_feed_client.py +++ b/sdk/storage/azure-storage-blob-changefeed/azure/storage/blob/changefeed/_change_feed_client.py @@ -4,20 +4,21 @@ # license information. # -------------------------------------------------------------------------- # pylint: disable=too-many-lines,no-self-use -from typing import ( # pylint: disable=unused-import - Optional, Any, TYPE_CHECKING, Dict +from typing import ( + Any, Dict, Optional, Union, + TYPE_CHECKING ) from azure.core.paging import ItemPaged from azure.storage.blob import BlobServiceClient # pylint: disable=no-name-in-module - from azure.storage.blob._shared.base_client import parse_connection_str from ._models import ChangeFeedPaged + if TYPE_CHECKING: - from datetime import datetime + from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential -class ChangeFeedClient(object): # pylint: disable=too-many-public-methods +class ChangeFeedClient(object): """A client to interact with a specific account change feed. :param str account_url: @@ -52,19 +53,18 @@ class ChangeFeedClient(object): # pylint: disable=too-many-public-methods :caption: Creating the ChangeFeedClient from a URL to a public blob (no auth needed). """ def __init__( - self, account_url, # type: str - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Any - ): - # type: (...) -> None + self, account_url: str, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> None: self._blob_service_client = BlobServiceClient(account_url, credential, **kwargs) @classmethod def from_connection_string( - cls, conn_str, # type: str - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long - **kwargs # type: Any - ): # type: (...) -> ChangeFeedClient + cls, conn_str: str, + credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long + **kwargs: Any + ) -> "ChangeFeedClient": """Create ChangeFeedClient from a Connection String. :param str conn_str: @@ -95,8 +95,7 @@ def from_connection_string( kwargs['secondary_hostname'] = secondary return cls(account_url, credential=credential, **kwargs) - def list_changes(self, **kwargs): - # type: (**Any) -> ItemPaged[Dict] + def list_changes(self, **kwargs: Any) -> ItemPaged[Dict]: """Returns a generator to list the change feed events. The generator will lazily follow the continuation tokens returned by the service. From 74d543915ab957d5957b1adebb9492409eb809b2 Mon Sep 17 00:00:00 2001 From: Jacob Lauzon Date: Mon, 10 Oct 2022 17:22:56 -0700 Subject: [PATCH 4/5] Add typing_extensions dep --- sdk/storage/azure-storage-file-share/setup.py | 3 ++- sdk/storage/azure-storage-queue/setup.py | 3 ++- shared_requirements.txt | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/sdk/storage/azure-storage-file-share/setup.py b/sdk/storage/azure-storage-file-share/setup.py index 69532fadfc59..0ad56cc09502 100644 --- a/sdk/storage/azure-storage-file-share/setup.py +++ b/sdk/storage/azure-storage-file-share/setup.py @@ -65,6 +65,7 @@ install_requires=[ "azure-core<2.0.0,>=1.24.2", "msrest>=0.7.1", - "cryptography>=2.1.4" + "cryptography>=2.1.4", + "typing-extensions>=4.0.1" ], ) diff --git a/sdk/storage/azure-storage-queue/setup.py b/sdk/storage/azure-storage-queue/setup.py index e071d661ec04..c1b0c7016142 100644 --- a/sdk/storage/azure-storage-queue/setup.py +++ b/sdk/storage/azure-storage-queue/setup.py @@ -68,6 +68,7 @@ install_requires=[ "azure-core<2.0.0,>=1.24.2", "msrest>=0.7.1", - "cryptography>=2.1.4" + "cryptography>=2.1.4", + "typing-extensions>=4.0.1" ], ) diff --git a/shared_requirements.txt b/shared_requirements.txt index 3c88f6d713e4..5762eb76307f 100644 --- a/shared_requirements.txt +++ b/shared_requirements.txt @@ -164,8 +164,10 @@ yarl<2.0,>=1.0 #override azure-storage-blob-changefeed azure-storage-blob>=12.5.0,<13.0.0 #override azure-storage-queue azure-core<2.0.0,>=1.24.2 #override azure-storage-queue msrest>=0.7.1 +#override azure-storage-queue typing-extensions>=4.0.1 #override azure-storage-file-share azure-core<2.0.0,>=1.24.2 #override azure-storage-file-share msrest>=0.7.1 +#override azure-storage-file-share typing-extensions>=4.0.1 #override azure-storage-file-datalake azure-core<2.0.0,>=1.24.2 #override azure-storage-file-datalake msrest>=0.7.1 #override azure-storage-file-datalake azure-storage-blob<13.0.0,>=12.14.0 From 1d2221a8ff7913ff69b9c00be57ef0e7ccdbf6b4 Mon Sep 17 00:00:00 2001 From: Jacob Lauzon Date: Tue, 11 Oct 2022 17:06:22 -0700 Subject: [PATCH 5/5] Update CHANGELOGs --- sdk/storage/azure-storage-file-share/CHANGELOG.md | 1 + sdk/storage/azure-storage-queue/CHANGELOG.md | 1 + 2 files changed, 2 insertions(+) diff --git a/sdk/storage/azure-storage-file-share/CHANGELOG.md b/sdk/storage/azure-storage-file-share/CHANGELOG.md index 65d6033b0f3e..50a87716fc53 100644 --- a/sdk/storage/azure-storage-file-share/CHANGELOG.md +++ b/sdk/storage/azure-storage-file-share/CHANGELOG.md @@ -9,6 +9,7 @@ ### Bugs Fixed ### Other Changes +- Added `typing-extensions>=4.0.1` as a dependency. ## 12.10.0 (2022-10-11) diff --git a/sdk/storage/azure-storage-queue/CHANGELOG.md b/sdk/storage/azure-storage-queue/CHANGELOG.md index a4af35d4522e..dec36c268cd6 100644 --- a/sdk/storage/azure-storage-queue/CHANGELOG.md +++ b/sdk/storage/azure-storage-queue/CHANGELOG.md @@ -9,6 +9,7 @@ ### Bugs Fixed ### Other Changes +- Added `typing-extensions>=4.0.1` as a dependency. ## 12.5.0 (2022-10-11)