Skip to content

Commit 524fd74

Browse files
authored
[Storage]fix type annotation (Azure#20096)
1 parent 8af1100 commit 524fd74

File tree

7 files changed

+49
-27
lines changed

7 files changed

+49
-27
lines changed

sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from io import BytesIO
99
from typing import ( # pylint: disable=unused-import
1010
Union, Optional, Any, IO, Iterable, AnyStr, Dict, List, Tuple,
11-
TYPE_CHECKING
12-
)
11+
TYPE_CHECKING,
12+
TypeVar, Type)
1313

1414
try:
1515
from urllib.parse import urlparse, quote, unquote
@@ -74,6 +74,8 @@
7474
'The require_encryption flag is set, but encryption is not supported'
7575
' for this method.')
7676

77+
ClassType = TypeVar("ClassType")
78+
7779

7880
class BlobClient(StorageAccountHostsMixin): # pylint: disable=too-many-public-methods
7981
"""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):
202204

203205
@classmethod
204206
def from_blob_url(cls, blob_url, credential=None, snapshot=None, **kwargs):
205-
# type: (str, Optional[Any], Optional[Union[str, Dict[str, Any]]], Any) -> BlobClient
207+
# type: (Type[ClassType], str, Optional[Any], Optional[Union[str, Dict[str, Any]]], Any) -> ClassType
206208
"""Create BlobClient from a blob url. This doesn't support customized blob url with '/' in blob name.
207209
208210
:param str blob_url:
@@ -272,13 +274,14 @@ def from_blob_url(cls, blob_url, credential=None, snapshot=None, **kwargs):
272274

273275
@classmethod
274276
def from_connection_string(
275-
cls, conn_str, # type: str
277+
cls, # type: Type[ClassType]
278+
conn_str, # type: str
276279
container_name, # type: str
277280
blob_name, # type: str
278281
snapshot=None, # type: Optional[str]
279282
credential=None, # type: Optional[Any]
280283
**kwargs # type: Any
281-
): # type: (...) -> BlobClient
284+
): # type: (...) -> ClassType
282285
"""Create BlobClient from a Connection String.
283286
284287
:param str conn_str:

sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import warnings
99
from typing import ( # pylint: disable=unused-import
1010
Union, Optional, Any, Iterable, Dict, List,
11-
TYPE_CHECKING
12-
)
11+
TYPE_CHECKING,
12+
TypeVar)
1313

1414

1515
try:
@@ -52,6 +52,8 @@
5252
FilteredBlob
5353
)
5454

55+
ClassType = TypeVar("ClassType")
56+
5557

5658
class BlobServiceClient(StorageAccountHostsMixin):
5759
"""A client to interact with the Blob Service at the account level.
@@ -144,10 +146,11 @@ def _format_url(self, hostname):
144146

145147
@classmethod
146148
def from_connection_string(
147-
cls, conn_str, # type: str
149+
cls, # type: Type[ClassType]
150+
conn_str, # type: str
148151
credential=None, # type: Optional[Any]
149152
**kwargs # type: Any
150-
): # type: (...) -> BlobServiceClient
153+
): # type: (...) -> ClassType
151154
"""Create BlobServiceClient from a Connection String.
152155
153156
:param str conn_str:

sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import functools
99
from typing import ( # pylint: disable=unused-import
1010
Union, Optional, Any, Iterable, AnyStr, Dict, List, Tuple, IO, Iterator,
11-
TYPE_CHECKING
12-
)
11+
TYPE_CHECKING,
12+
TypeVar)
1313

1414

1515
try:
@@ -69,6 +69,9 @@ def _get_blob_name(blob):
6969
return blob
7070

7171

72+
ClassType = TypeVar("ClassType")
73+
74+
7275
class ContainerClient(StorageAccountHostsMixin): # pylint: disable=too-many-public-methods
7376
"""A client to interact with a specific container, although that container
7477
may not yet exist.
@@ -170,7 +173,7 @@ def _format_url(self, hostname):
170173

171174
@classmethod
172175
def from_container_url(cls, container_url, credential=None, **kwargs):
173-
# type: (str, Optional[Any], Any) -> ContainerClient
176+
# type: (Type[ClassType], str, Optional[Any], Any) -> ClassType
174177
"""Create ContainerClient from a container url.
175178
176179
:param str container_url:
@@ -213,11 +216,12 @@ def from_container_url(cls, container_url, credential=None, **kwargs):
213216

214217
@classmethod
215218
def from_connection_string(
216-
cls, conn_str, # type: str
219+
cls, # type: Type[ClassType]
220+
conn_str, # type: str
217221
container_name, # type: str
218222
credential=None, # type: Optional[Any]
219223
**kwargs # type: Any
220-
): # type: (...) -> ContainerClient
224+
): # type: (...) -> ClassType
221225
"""Create ContainerClient from a Connection String.
222226
223227
:param str conn_str:

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Licensed under the MIT License. See License.txt in the project root for
44
# license information.
55
# --------------------------------------------------------------------------
6-
from typing import Any
6+
from typing import Any, TypeVar
77

88
try:
99
from urllib.parse import quote, unquote
@@ -16,6 +16,8 @@
1616
from ._models import DirectoryProperties, FileProperties
1717
from ._path_client import PathClient
1818

19+
ClassType = TypeVar("ClassType")
20+
1921

2022
class DataLakeDirectoryClient(PathClient):
2123
"""A client to interact with the DataLake directory, even if the directory may not yet exist.
@@ -67,12 +69,13 @@ def __init__(
6769

6870
@classmethod
6971
def from_connection_string(
70-
cls, conn_str, # type: str
72+
cls, # type: Type[ClassType]
73+
conn_str, # type: str
7174
file_system_name, # type: str
7275
directory_name, # type: str
7376
credential=None, # type: Optional[Any]
7477
**kwargs # type: Any
75-
): # type: (...) -> DataLakeDirectoryClient
78+
): # type: (...) -> ClassType
7679
"""
7780
Create DataLakeDirectoryClient from a Connection String.
7881

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_file_client.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# license information.
55
# --------------------------------------------------------------------------
66
from io import BytesIO
7-
from typing import Any
7+
from typing import Any, TypeVar
88

99
try:
1010
from urllib.parse import quote, unquote
@@ -27,6 +27,8 @@
2727
from ._deserialize import process_storage_error, deserialize_file_properties
2828
from ._models import FileProperties, DataLakeFileQueryError
2929

30+
ClassType = TypeVar("ClassType")
31+
3032

3133
class DataLakeFileClient(PathClient):
3234
"""A client to interact with the DataLake file, even if the file may not yet exist.
@@ -76,12 +78,13 @@ def __init__(
7678

7779
@classmethod
7880
def from_connection_string(
79-
cls, conn_str, # type: str
81+
cls, # type: Type[ClassType]
82+
conn_str, # type: str
8083
file_system_name, # type: str
8184
file_path, # type: str
8285
credential=None, # type: Optional[Any]
8386
**kwargs # type: Any
84-
): # type: (...) -> DataLakeFileClient
87+
): # type: (...) -> ClassType
8588
"""
8689
Create DataLakeFileClient from a Connection String.
8790

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_service_client.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Licensed under the MIT License. See License.txt in the project root for
44
# license information.
55
# --------------------------------------------------------------------------
6-
from typing import Optional, Dict, Any
6+
from typing import Optional, Dict, Any, TypeVar
77

88
try:
99
from urllib.parse import urlparse
@@ -23,6 +23,8 @@
2323
from ._serialize import convert_dfs_url_to_blob_url, get_api_version
2424
from ._generated import AzureDataLakeStorageRESTAPI
2525

26+
ClassType = TypeVar("ClassType")
27+
2628

2729
class DataLakeServiceClient(StorageAccountHostsMixin):
2830
"""A client to interact with the DataLake Service at the account level.
@@ -120,10 +122,11 @@ def _format_url(self, hostname):
120122

121123
@classmethod
122124
def from_connection_string(
123-
cls, conn_str, # type: str
125+
cls, # type: Type[ClassType]
126+
conn_str, # type: str
124127
credential=None, # type: Optional[Any]
125128
**kwargs # type: Any
126-
): # type: (...) -> DataLakeServiceClient
129+
): # type: (...) -> ClassType
127130
"""
128131
Create DataLakeServiceClient from a Connection String.
129132

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
# license information.
55
# --------------------------------------------------------------------------
66
import functools
7-
from typing import Optional, Any, Union, Iterator
8-
7+
from typing import Optional, Any, Union, TypeVar, Iterator
98

109
try:
1110
from urllib.parse import urlparse, quote, unquote
@@ -32,6 +31,9 @@
3231
from ._deserialize import deserialize_path_properties, process_storage_error, is_file_path
3332

3433

34+
ClassType = TypeVar("ClassType")
35+
36+
3537
class FileSystemClient(StorageAccountHostsMixin):
3638
"""A client to interact with a specific file system, even if that file system
3739
may not yet exist.
@@ -137,11 +139,12 @@ def close(self):
137139

138140
@classmethod
139141
def from_connection_string(
140-
cls, conn_str, # type: str
142+
cls, # type: Type[ClassType]
143+
conn_str, # type: str
141144
file_system_name, # type: str
142145
credential=None, # type: Optional[Any]
143146
**kwargs # type: Any
144-
): # type: (...) -> FileSystemClient
147+
): # type: (...) -> ClassType
145148
"""
146149
Create FileSystemClient from a Connection String.
147150

0 commit comments

Comments
 (0)