Skip to content

Commit

Permalink
[Storage]fix type annotation (#20096)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiafu-msft authored Oct 15, 2021
1 parent 8af1100 commit 524fd74
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -52,6 +52,8 @@
FilteredBlob
)

ClassType = TypeVar("ClassType")


class BlobServiceClient(StorageAccountHostsMixin):
"""A client to interact with the Blob Service at the account level.
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 524fd74

Please sign in to comment.