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 957384e1c1d0..675b5a5e72c0 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. @@ -202,7 +204,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: @@ -272,13 +274,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 2b8a99a2fa9b..9dddb113ff72 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. @@ -144,10 +146,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 afa10add6feb..8b0a96ba55f7 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. @@ -170,7 +173,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: @@ -213,11 +216,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 042fa0551590..49aac0887889 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 776b98cda9d6..dfd5ca5b6e5d 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 @@ -23,6 +23,8 @@ from ._serialize import convert_dfs_url_to_blob_url, get_api_version from ._generated import AzureDataLakeStorageRESTAPI +ClassType = TypeVar("ClassType") + class DataLakeServiceClient(StorageAccountHostsMixin): """A client to interact with the DataLake Service at the account level. @@ -120,10 +122,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 b6f7c4c6299e..5026c96d2426 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, Iterator - +from typing import Optional, Any, Union, TypeVar, Iterator try: from urllib.parse import urlparse, quote, unquote @@ -32,6 +31,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. @@ -137,11 +139,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.