Skip to content

Commit 972ebbb

Browse files
[Storage] Fixed next-mypy for azure-storage-blob, azure-storage-file-share, and azure-storage-queue (Azure#38835)
1 parent e45938e commit 972ebbb

File tree

12 files changed

+31
-7
lines changed

12 files changed

+31
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def __init__(
116116

117117
# For a parallel download, the stream is always seekable, so we note down the current position
118118
# in order to seek to the right place when out-of-order chunks come in
119-
self.stream_start = stream.tell() if parallel else None
119+
self.stream_start = stream.tell() if parallel else 0
120120

121121
# Download progress so far
122122
self.progress_total = current_progress

sdk/storage/azure-storage-blob/azure/storage/blob/_shared/base_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def __exit__(self, *args):
363363

364364

365365
def _format_shared_key_credential(
366-
account_name: str,
366+
account_name: Optional[str],
367367
credential: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "AsyncTokenCredential", TokenCredential]] = None # pylint: disable=line-too-long
368368
) -> Any:
369369
if isinstance(credential, str):

sdk/storage/azure-storage-blob/samples/blob_samples_authentication.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ def auth_shared_access_signature(self):
9595
# Instantiate a BlobServiceClient using a connection string
9696
from azure.storage.blob import BlobServiceClient
9797
blob_service_client = BlobServiceClient.from_connection_string(self.connection_string)
98+
if blob_service_client.account_name is None:
99+
print("Connection string did not provide an account name." + '\n' +
100+
"Test: auth_shared_access_signature")
101+
sys.exit(1)
98102

99103
# [START create_sas_token]
100104
# Create a SAS token to use to authenticate a new client

sdk/storage/azure-storage-blob/samples/blob_samples_authentication_async.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ async def auth_shared_access_signature_async(self):
9191
# Instantiate a BlobServiceClient using a connection string
9292
from azure.storage.blob.aio import BlobServiceClient
9393
blob_service_client = BlobServiceClient.from_connection_string(self.connection_string)
94+
if blob_service_client.account_name is None:
95+
print("Connection string did not provide an account name." + '\n' +
96+
"Test: auth_shared_access_signature_async")
97+
sys.exit(1)
9498

9599
# [START create_sas_token]
96100
# Create a SAS token to use to authenticate a new client

sdk/storage/azure-storage-blob/samples/blob_samples_containers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ def container_access_policy(self):
138138

139139
# Instantiate a ContainerClient
140140
container_client = blob_service_client.get_container_client("myaccesscontainer")
141+
if container_client.account_name is None:
142+
print("Connection string did not provide an account name." + '\n' +
143+
"Test: container_access_policy")
144+
sys.exit(1)
141145

142146
try:
143147
# Create new Container

sdk/storage/azure-storage-blob/samples/blob_samples_containers_async.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ async def container_access_policy_async(self):
136136
async with blob_service_client:
137137
# Instantiate a ContainerClient
138138
container_client = blob_service_client.get_container_client("myaccesscontainerasync")
139+
if container_client.account_name is None:
140+
print("Connection string did not provide an account name." + '\n' +
141+
"Test: container_access_policy_async")
142+
sys.exit(1)
139143

140144
try:
141145
# Create new Container

sdk/storage/azure-storage-file-share/azure/storage/fileshare/_download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(
6565

6666
# For a parallel download, the stream is always seekable, so we note down the current position
6767
# in order to seek to the right place when out-of-order chunks come in
68-
self.stream_start = stream.tell() if parallel else None
68+
self.stream_start = stream.tell() if parallel else 0
6969

7070
# Download progress so far
7171
self.progress_total = current_progress

sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/base_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def __exit__(self, *args):
363363

364364

365365
def _format_shared_key_credential(
366-
account_name: str,
366+
account_name: Optional[str],
367367
credential: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "AsyncTokenCredential", TokenCredential]] = None # pylint: disable=line-too-long
368368
) -> Any:
369369
if isinstance(credential, str):

sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def __exit__(self, *args):
363363

364364

365365
def _format_shared_key_credential(
366-
account_name: str,
366+
account_name: Optional[str],
367367
credential: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "AsyncTokenCredential", TokenCredential]] = None # pylint: disable=line-too-long
368368
) -> Any:
369369
if isinstance(credential, str):

sdk/storage/azure-storage-queue/samples/queue_samples_authentication_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ async def authentication_by_shared_access_signature_async(self):
110110
from azure.storage.queue import generate_account_sas, ResourceTypes, AccountSasPermissions
111111

112112
sas_token = generate_account_sas(
113-
queue_service.account_name,
114-
queue_service.credential.account_key,
113+
self.account_name,
114+
self.access_key,
115115
resource_types=ResourceTypes(service=True),
116116
permission=AccountSasPermissions(read=True),
117117
expiry=datetime.utcnow() + timedelta(hours=1)

0 commit comments

Comments
 (0)