Skip to content

Commit 33d42ea

Browse files
[Storage] [Next-Pylint] Blob Package (Azure#30676)
* Pylint * Pylint 2 * Pop back in no-self-use since current pipeline uses it * Fix failing test * Fixes * revert pylintrc * Skip dunder * Add back in dunder to appease current pylint
1 parent ee3db5f commit 33d42ea

31 files changed

+118
-174
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def download_blob_from_url(
179179
_download_to_stream(client, output, **kwargs)
180180
else:
181181
if not overwrite and os.path.isfile(output):
182-
raise ValueError("The file '{}' already exists.".format(output))
182+
raise ValueError(f"The file '{output}' already exists.")
183183
with open(output, 'wb') as file_handle:
184184
_download_to_stream(client, file_handle, **kwargs)
185185

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

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def __init__(
166166
if not (container_name and blob_name):
167167
raise ValueError("Please specify a container name and blob name.")
168168
if not parsed_url.netloc:
169-
raise ValueError("Invalid URL: {}".format(account_url))
169+
raise ValueError(f"Invalid URL: {account_url}")
170170

171171
path_snapshot, sas_token = parse_query(parsed_url.query)
172172

@@ -192,20 +192,15 @@ def _format_url(self, hostname):
192192
container_name = self.container_name
193193
if isinstance(container_name, str):
194194
container_name = container_name.encode('UTF-8')
195-
return "{}://{}/{}/{}{}".format(
196-
self.scheme,
197-
hostname,
198-
quote(container_name),
199-
quote(self.blob_name, safe='~/'),
200-
self._query_str)
195+
return f"{self.scheme}://{hostname}/{quote(container_name)}/{quote(self.blob_name, safe='~/')}{self._query_str}"
201196

202197
def _encode_source_url(self, source_url):
203198
parsed_source_url = urlparse(source_url)
204199
source_scheme = parsed_source_url.scheme
205200
source_hostname = parsed_source_url.netloc.rstrip('/')
206201
source_path = unquote(parsed_source_url.path)
207202
source_query = parsed_source_url.query
208-
result = ["{}://{}{}".format(source_scheme, source_hostname, quote(source_path, safe='~/'))]
203+
result = [f"{source_scheme}://{source_hostname}{quote(source_path, safe='~/')}"]
209204
if source_query:
210205
result.append(source_query)
211206
return '?'.join(result)
@@ -248,7 +243,7 @@ def from_blob_url(
248243
parsed_url = urlparse(blob_url.rstrip('/'))
249244

250245
if not parsed_url.netloc:
251-
raise ValueError("Invalid URL: {}".format(blob_url))
246+
raise ValueError(f"Invalid URL: {blob_url}")
252247

253248
account_path = ""
254249
if ".core." in parsed_url.netloc:
@@ -263,11 +258,7 @@ def from_blob_url(
263258
if len(path_blob) > 2:
264259
account_path = "/" + "/".join(path_blob[:-2])
265260

266-
account_url = "{}://{}{}?{}".format(
267-
parsed_url.scheme,
268-
parsed_url.netloc.rstrip('/'),
269-
account_path,
270-
parsed_url.query)
261+
account_url = f"{parsed_url.scheme}://{parsed_url.netloc.rstrip('/')}{account_path}?{parsed_url.query}"
271262

272263
msg_invalid_url = "Invalid URL. Provide a blob_url with a valid blob and container name."
273264
if len(path_blob) <= 1:
@@ -389,7 +380,7 @@ def _upload_blob_options( # pylint:disable=too-many-statements
389380
elif hasattr(data, '__aiter__'):
390381
stream = AsyncIterStreamer(data, encoding=encoding)
391382
else:
392-
raise TypeError("Unsupported data type: {}".format(type(data)))
383+
raise TypeError(f"Unsupported data type: {type(data)}")
393384

394385
validate_content = kwargs.pop('validate_content', False)
395386
content_settings = kwargs.pop('content_settings', None)
@@ -440,7 +431,7 @@ def _upload_blob_options( # pylint:disable=too-many-statements
440431
raise ValueError(_ERROR_UNSUPPORTED_METHOD_FOR_ENCRYPTION)
441432
kwargs['client'] = self._client.append_blob
442433
else:
443-
raise ValueError("Unsupported BlobType: {}".format(blob_type))
434+
raise ValueError(f"Unsupported BlobType: {blob_type}")
444435
return kwargs
445436

446437
def _upload_blob_from_url_options(self, source_url, **kwargs):
@@ -3469,7 +3460,7 @@ def _upload_page_options( # type: ignore
34693460
if length is None or length % 512 != 0:
34703461
raise ValueError("length must be an integer that aligns with 512 page size")
34713462
end_range = offset + length - 1 # Reformat to an inclusive range index
3472-
content_range = 'bytes={0}-{1}'.format(offset, end_range) # type: ignore
3463+
content_range = f'bytes={offset}-{end_range}' # type: ignore
34733464
access_conditions = get_access_conditions(kwargs.pop('lease', None))
34743465
seq_conditions = SequenceNumberAccessConditions(
34753466
if_sequence_number_less_than_or_equal_to=kwargs.pop('if_sequence_number_lte', None),
@@ -3622,8 +3613,8 @@ def _upload_pages_from_url_options( # type: ignore
36223613

36233614
# Format range
36243615
end_range = offset + length - 1
3625-
destination_range = 'bytes={0}-{1}'.format(offset, end_range)
3626-
source_range = 'bytes={0}-{1}'.format(source_offset, source_offset + length - 1) # should subtract 1 here?
3616+
destination_range = f'bytes={offset}-{end_range}'
3617+
source_range = f'bytes={source_offset}-{source_offset + length - 1}' # should subtract 1 here?
36273618

36283619
seq_conditions = SequenceNumberAccessConditions(
36293620
if_sequence_number_less_than_or_equal_to=kwargs.pop('if_sequence_number_lte', None),
@@ -3796,7 +3787,7 @@ def _clear_page_options(self, offset, length, **kwargs):
37963787
if length is None or length % 512 != 0:
37973788
raise ValueError("length must be an integer that aligns with 512 page size")
37983789
end_range = length + offset - 1 # Reformat to an inclusive range index
3799-
content_range = 'bytes={0}-{1}'.format(offset, end_range)
3790+
content_range = f'bytes={offset}-{end_range}'
38003791

38013792
cpk = kwargs.pop('cpk', None)
38023793
cpk_info = None
@@ -4054,9 +4045,9 @@ def _append_block_from_url_options( # type: ignore
40544045
source_range = None
40554046
if source_length is not None:
40564047
end_range = source_offset + source_length - 1
4057-
source_range = 'bytes={0}-{1}'.format(source_offset, end_range)
4048+
source_range = f'bytes={source_offset}-{end_range}'
40584049
elif source_offset is not None:
4059-
source_range = "bytes={0}-".format(source_offset)
4050+
source_range = f"bytes={source_offset}-"
40604051

40614052
appendpos_condition = kwargs.pop('appendpos_condition', None)
40624053
maxsize_condition = kwargs.pop('maxsize_condition', None)
@@ -4307,7 +4298,7 @@ def _get_container_client(self): # pylint: disable=client-method-missing-kwargs
43074298
else:
43084299
_pipeline = self._pipeline # pylint: disable = protected-access
43094300
return ContainerClient(
4310-
"{}://{}".format(self.scheme, self.primary_hostname), container_name=self.container_name,
4301+
f"{self.scheme}://{self.primary_hostname}", container_name=self.container_name,
43114302
credential=self._raw_credential, api_version=self.api_version, _configuration=self._config,
43124303
_pipeline=_pipeline, _location_mode=self._location_mode, _hosts=self._hosts,
43134304
require_encryption=self.require_encryption, encryption_version=self.encryption_version,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def __init__(
130130
raise ValueError("Account URL must be a string.")
131131
parsed_url = urlparse(account_url.rstrip('/'))
132132
if not parsed_url.netloc:
133-
raise ValueError("Invalid URL: {}".format(account_url))
133+
raise ValueError(f"Invalid URL: {account_url}")
134134

135135
_, sas_token = parse_query(parsed_url.query)
136136
self._query_str, credential = self._format_query_string(sas_token, credential)
@@ -143,7 +143,7 @@ def _format_url(self, hostname):
143143
"""Format the endpoint URL according to the current location
144144
mode hostname.
145145
"""
146-
return "{}://{}/{}".format(self.scheme, hostname, self._query_str)
146+
return f"{self.scheme}://{hostname}/{self._query_str}"
147147

148148
@classmethod
149149
def from_connection_string(

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

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def __init__(
150150
if not container_name:
151151
raise ValueError("Please specify a container name.")
152152
if not parsed_url.netloc:
153-
raise ValueError("Invalid URL: {}".format(account_url))
153+
raise ValueError(f"Invalid URL: {account_url}")
154154

155155
_, sas_token = parse_query(parsed_url.query)
156156
self.container_name = container_name
@@ -171,11 +171,7 @@ def _format_url(self, hostname):
171171
container_name = self.container_name
172172
if isinstance(container_name, str):
173173
container_name = container_name.encode('UTF-8')
174-
return "{}://{}/{}{}".format(
175-
self.scheme,
176-
hostname,
177-
quote(container_name),
178-
self._query_str)
174+
return f"{self.scheme}://{hostname}/{quote(container_name)}{self._query_str}"
179175

180176
@classmethod
181177
def from_container_url(
@@ -209,17 +205,13 @@ def from_container_url(
209205
raise ValueError("Container URL must be a string.")
210206
parsed_url = urlparse(container_url)
211207
if not parsed_url.netloc:
212-
raise ValueError("Invalid URL: {}".format(container_url))
208+
raise ValueError(f"Invalid URL: {container_url}")
213209

214210
container_path = parsed_url.path.strip('/').split('/')
215211
account_path = ""
216212
if len(container_path) > 1:
217213
account_path = "/" + "/".join(container_path[:-1])
218-
account_url = "{}://{}{}?{}".format(
219-
parsed_url.scheme,
220-
parsed_url.netloc.rstrip('/'),
221-
account_path,
222-
parsed_url.query)
214+
account_url = f"{parsed_url.scheme}://{parsed_url.netloc.rstrip('/')}{account_path}?{parsed_url.query}"
223215
container_name = unquote(container_path[-1])
224216
if not container_name:
225217
raise ValueError("Invalid URL. Please provide a URL with a valid container name")
@@ -347,7 +339,7 @@ def _rename_container(self, new_name, **kwargs):
347339
kwargs['source_lease_id'] = lease
348340
try:
349341
renamed_container = ContainerClient(
350-
"{}://{}".format(self.scheme, self.primary_hostname), container_name=new_name,
342+
f"{self.scheme}://{self.primary_hostname}", container_name=new_name,
351343
credential=self.credential, api_version=self.api_version, _configuration=self._config,
352344
_pipeline=self._pipeline, _location_mode=self._location_mode, _hosts=self._hosts,
353345
require_encryption=self.require_encryption, encryption_version=self.encryption_version,
@@ -655,7 +647,7 @@ def _get_blob_service_client(self): # pylint: disable=client-method-missing-kwa
655647
else:
656648
_pipeline = self._pipeline # pylint: disable = protected-access
657649
return BlobServiceClient(
658-
"{}://{}".format(self.scheme, self.primary_hostname),
650+
f"{self.scheme}://{self.primary_hostname}",
659651
credential=self._raw_credential, api_version=self.api_version, _configuration=self._config,
660652
_location_mode=self._location_mode, _hosts=self._hosts, require_encryption=self.require_encryption,
661653
encryption_version=self.encryption_version, key_encryption_key=self.key_encryption_key,
@@ -1407,7 +1399,7 @@ def _generate_delete_blobs_options(
14071399

14081400
req = HttpRequest(
14091401
"DELETE",
1410-
"/{}/{}{}".format(quote(container_name), quote(blob_name, safe='/~'), self._query_str),
1402+
f"/{quote(container_name)}/{quote(blob_name, safe='/~')}{self._query_str}",
14111403
headers=header_parameters
14121404
)
14131405
req.format_parameters(query_parameters)
@@ -1507,7 +1499,7 @@ def delete_blobs(
15071499
:caption: Deleting multiple blobs.
15081500
"""
15091501
if len(blobs) == 0:
1510-
return iter(list())
1502+
return iter([])
15111503

15121504
reqs, options = self._generate_delete_blobs_options(*blobs, **kwargs)
15131505

@@ -1593,7 +1585,7 @@ def _generate_set_tiers_options(
15931585

15941586
req = HttpRequest(
15951587
"PUT",
1596-
"/{}/{}{}".format(quote(container_name), quote(blob_name, safe='/~'), self._query_str),
1588+
f"/{quote(container_name)}/{quote(blob_name, safe='/~')}{self._query_str}",
15971589
headers=header_parameters
15981590
)
15991591
req.format_parameters(query_parameters)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Licensed under the MIT License. See License.txt in the project root for
44
# license information.
55
# --------------------------------------------------------------------------
6-
# pylint: disable=no-self-use
76

87
from typing import (
98
Dict, List, Optional, Tuple, Union,
@@ -76,7 +75,7 @@ def deserialize_ors_policies(policy_dictionary):
7675
rule_id = policy_and_rule_ids[1]
7776

7877
# If we are seeing this policy for the first time, create a new list to store rule_id -> result
79-
parsed_result[policy_id] = parsed_result.get(policy_id) or list()
78+
parsed_result[policy_id] = parsed_result.get(policy_id) or []
8079
parsed_result[policy_id].append(ObjectReplicationRule(rule_id=rule_id, status=val))
8180

8281
result_list = [ObjectReplicationPolicy(policy_id=k, rules=v) for k, v in parsed_result.items()]

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,7 @@ def __init__(
373373
self.properties.size = self.size
374374

375375
# Overwrite the content range to the user requested range
376-
self.properties.content_range = "bytes {0}-{1}/{2}".format(
377-
self._start_range,
378-
self._end_range,
379-
self._file_size
380-
)
376+
self.properties.content_range = f"bytes {self._start_range}-{self._end_range}/{self._file_size}"
381377

382378
# Overwrite the content MD5 as it is the MD5 for the last range instead
383379
# of the stored MD5
@@ -456,8 +452,8 @@ def _initial_request(self):
456452
download_stream_current=0,
457453
**self._request_options
458454
)
459-
except HttpResponseError as error:
460-
process_storage_error(error)
455+
except HttpResponseError as e:
456+
process_storage_error(e)
461457

462458
# Set the download size to empty
463459
self.size = 0

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
def _validate_not_none(param_name, param):
4343
if param is None:
44-
raise ValueError('{0} should not be None.'.format(param_name))
44+
raise ValueError(f'{param_name} should not be None.')
4545

4646

4747
def _validate_key_encryption_key_wrap(kek):

sdk/storage/azure-storage-blob/azure/storage/blob/_generated/_configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(self, url: str, **kwargs: Any) -> None:
3737

3838
self.url = url
3939
self.version = version
40-
kwargs.setdefault("sdk_moniker", "azureblobstorage/{}".format(VERSION))
40+
kwargs.setdefault("sdk_moniker", f"azureblobstorage/{VERSION}")
4141
self._configure(**kwargs)
4242

4343
def _configure(

sdk/storage/azure-storage-blob/azure/storage/blob/_generated/_serialization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1967,4 +1967,4 @@ def deserialize_unix(attr):
19671967
msg = "Cannot deserialize to unix datetime object."
19681968
raise_with_traceback(DeserializationError, msg, err)
19691969
else:
1970-
return date_obj
1970+
return date_obj

sdk/storage/azure-storage-blob/azure/storage/blob/_generated/_vendor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ def _format_url_section(template, **kwargs):
2424
except KeyError as key:
2525
formatted_components = template.split("/")
2626
components = [c for c in formatted_components if "{}".format(key.args[0]) not in c]
27-
template = "/".join(components)
27+
template = "/".join(components)

0 commit comments

Comments
 (0)