From 243cba56558604dd96dc8a75677b3b3ac4fcced5 Mon Sep 17 00:00:00 2001 From: xiafu Date: Wed, 4 Aug 2021 15:41:34 -0700 Subject: [PATCH] [Storage]fix type annotation --- .../azure/storage/blob/_blob_client.py | 13 ++++++++----- .../azure/storage/blob/_blob_service_client.py | 11 +++++++---- .../azure/storage/blob/_container_client.py | 14 +++++++++----- .../filedatalake/_data_lake_directory_client.py | 9 ++++++--- .../storage/filedatalake/_data_lake_file_client.py | 9 ++++++--- .../filedatalake/_data_lake_service_client.py | 9 ++++++--- .../storage/filedatalake/_file_system_client.py | 11 +++++++---- 7 files changed, 49 insertions(+), 27 deletions(-) diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py index 042f055eb0b9..2ceab6bc08cd 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py @@ -8,8 +8,8 @@ from io import BytesIO from typing import ( # pylint: disable=unused-import Union, Optional, Any, IO, Iterable, AnyStr, Dict, List, Tuple, - TYPE_CHECKING -) + TYPE_CHECKING, + TypeVar, Type) try: from urllib.parse import urlparse, quote, unquote @@ -74,6 +74,8 @@ 'The require_encryption flag is set, but encryption is not supported' ' for this method.') +ClassType = TypeVar("ClassType") + class BlobClient(StorageAccountHostsMixin): # pylint: disable=too-many-public-methods """A client to interact with a specific blob, although that blob may not yet exist. @@ -203,7 +205,7 @@ def _encode_source_url(self, source_url): @classmethod def from_blob_url(cls, blob_url, credential=None, snapshot=None, **kwargs): - # type: (str, Optional[Any], Optional[Union[str, Dict[str, Any]]], Any) -> BlobClient + # type: (Type[ClassType], str, Optional[Any], Optional[Union[str, Dict[str, Any]]], Any) -> ClassType """Create BlobClient from a blob url. This doesn't support customized blob url with '/' in blob name. :param str blob_url: @@ -273,13 +275,14 @@ def from_blob_url(cls, blob_url, credential=None, snapshot=None, **kwargs): @classmethod def from_connection_string( - cls, conn_str, # type: str + cls, # type: Type[ClassType] + conn_str, # type: str container_name, # type: str blob_name, # type: str snapshot=None, # type: Optional[str] credential=None, # type: Optional[Any] **kwargs # type: Any - ): # type: (...) -> BlobClient + ): # type: (...) -> ClassType """Create BlobClient from a Connection String. :param str conn_str: diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py index d277a094921a..234d5523804b 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py @@ -8,8 +8,8 @@ import warnings from typing import ( # pylint: disable=unused-import Union, Optional, Any, Iterable, Dict, List, - TYPE_CHECKING -) + TYPE_CHECKING, + TypeVar) try: @@ -52,6 +52,8 @@ FilteredBlob ) +ClassType = TypeVar("ClassType") + class BlobServiceClient(StorageAccountHostsMixin): """A client to interact with the Blob Service at the account level. @@ -145,10 +147,11 @@ def _format_url(self, hostname): @classmethod def from_connection_string( - cls, conn_str, # type: str + cls, # type: Type[ClassType] + conn_str, # type: str credential=None, # type: Optional[Any] **kwargs # type: Any - ): # type: (...) -> BlobServiceClient + ): # type: (...) -> ClassType """Create BlobServiceClient from a Connection String. :param str conn_str: 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 82bfe1b04110..e571704a3114 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 @@ -8,8 +8,8 @@ import functools from typing import ( # pylint: disable=unused-import Union, Optional, Any, Iterable, AnyStr, Dict, List, Tuple, IO, Iterator, - TYPE_CHECKING -) + TYPE_CHECKING, + TypeVar) try: @@ -69,6 +69,9 @@ def _get_blob_name(blob): return blob +ClassType = TypeVar("ClassType") + + class ContainerClient(StorageAccountHostsMixin): # pylint: disable=too-many-public-methods """A client to interact with a specific container, although that container may not yet exist. @@ -171,7 +174,7 @@ def _format_url(self, hostname): @classmethod def from_container_url(cls, container_url, credential=None, **kwargs): - # type: (str, Optional[Any], Any) -> ContainerClient + # type: (Type[ClassType], str, Optional[Any], Any) -> ClassType """Create ContainerClient from a container url. :param str container_url: @@ -214,11 +217,12 @@ def from_container_url(cls, container_url, credential=None, **kwargs): @classmethod def from_connection_string( - cls, conn_str, # type: str + cls, # type: Type[ClassType] + conn_str, # type: str container_name, # type: str credential=None, # type: Optional[Any] **kwargs # type: Any - ): # type: (...) -> ContainerClient + ): # type: (...) -> ClassType """Create ContainerClient from a Connection String. :param str conn_str: diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py index c42391e6071b..ff7122dd246d 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py @@ -3,7 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- -from typing import Any +from typing import Any, TypeVar try: from urllib.parse import quote, unquote @@ -16,6 +16,8 @@ from ._models import DirectoryProperties, FileProperties from ._path_client import PathClient +ClassType = TypeVar("ClassType") + class DataLakeDirectoryClient(PathClient): """A client to interact with the DataLake directory, even if the directory may not yet exist. @@ -67,12 +69,13 @@ def __init__( @classmethod def from_connection_string( - cls, conn_str, # type: str + cls, # type: Type[ClassType] + conn_str, # type: str file_system_name, # type: str directory_name, # type: str credential=None, # type: Optional[Any] **kwargs # type: Any - ): # type: (...) -> DataLakeDirectoryClient + ): # type: (...) -> ClassType """ Create DataLakeDirectoryClient from a Connection String. diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_file_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_file_client.py index fe074b3a49db..a06c1348908b 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_file_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_file_client.py @@ -4,7 +4,7 @@ # license information. # -------------------------------------------------------------------------- from io import BytesIO -from typing import Any +from typing import Any, TypeVar try: from urllib.parse import quote, unquote @@ -27,6 +27,8 @@ from ._deserialize import process_storage_error, deserialize_file_properties from ._models import FileProperties, DataLakeFileQueryError +ClassType = TypeVar("ClassType") + class DataLakeFileClient(PathClient): """A client to interact with the DataLake file, even if the file may not yet exist. @@ -76,12 +78,13 @@ def __init__( @classmethod def from_connection_string( - cls, conn_str, # type: str + cls, # type: Type[ClassType] + conn_str, # type: str file_system_name, # type: str file_path, # type: str credential=None, # type: Optional[Any] **kwargs # type: Any - ): # type: (...) -> DataLakeFileClient + ): # type: (...) -> ClassType """ Create DataLakeFileClient from a Connection String. diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_service_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_service_client.py index 211df05827c2..473cc9885124 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_service_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_service_client.py @@ -3,7 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- -from typing import Optional, Dict, Any +from typing import Optional, Dict, Any, TypeVar try: from urllib.parse import urlparse @@ -22,6 +22,8 @@ from ._models import UserDelegationKey, FileSystemPropertiesPaged, LocationMode from ._serialize import convert_dfs_url_to_blob_url +ClassType = TypeVar("ClassType") + class DataLakeServiceClient(StorageAccountHostsMixin): """A client to interact with the DataLake Service at the account level. @@ -116,10 +118,11 @@ def _format_url(self, hostname): @classmethod def from_connection_string( - cls, conn_str, # type: str + cls, # type: Type[ClassType] + conn_str, # type: str credential=None, # type: Optional[Any] **kwargs # type: Any - ): # type: (...) -> DataLakeServiceClient + ): # type: (...) -> ClassType """ Create DataLakeServiceClient from a Connection String. diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py index 94af506b5a3f..396dcba907df 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py @@ -4,8 +4,7 @@ # license information. # -------------------------------------------------------------------------- import functools -from typing import Optional, Any, Union - +from typing import Optional, Any, Union, TypeVar try: from urllib.parse import urlparse, quote, unquote @@ -31,6 +30,9 @@ from ._deserialize import deserialize_path_properties, process_storage_error, is_file_path +ClassType = TypeVar("ClassType") + + class FileSystemClient(StorageAccountHostsMixin): """A client to interact with a specific file system, even if that file system may not yet exist. @@ -133,11 +135,12 @@ def close(self): @classmethod def from_connection_string( - cls, conn_str, # type: str + cls, # type: Type[ClassType] + conn_str, # type: str file_system_name, # type: str credential=None, # type: Optional[Any] **kwargs # type: Any - ): # type: (...) -> FileSystemClient + ): # type: (...) -> ClassType """ Create FileSystemClient from a Connection String.