Skip to content

Commit

Permalink
[Storage] [Next Pylint] Oct next-pylint Patches (#37264)
Browse files Browse the repository at this point in the history
  • Loading branch information
weirongw23-msft authored Oct 7, 2024
1 parent ba5ef54 commit 9e01adc
Show file tree
Hide file tree
Showing 94 changed files with 345 additions and 331 deletions.
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.
# --------------------------------------------------------------------------
# pylint: disable=too-many-lines, docstring-keyword-should-match-keyword-only
# pylint: disable=docstring-keyword-should-match-keyword-only

from typing import (
Any, Dict, Optional, Union,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
# pylint: disable=too-few-public-methods, too-many-instance-attributes
# pylint: disable=super-init-not-called, too-many-lines
# pylint: disable=too-few-public-methods
import collections
import copy
import json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def __init__(
self._query_str, credential = self._format_query_string(sas_token, credential, snapshot=self.snapshot)
super(BlobClient, self).__init__(parsed_url, service='blob', credential=credential, **kwargs)
self._client = AzureBlobStorage(self.url, base_url=self.url, pipeline=self._pipeline)
self._client._config.version = get_api_version(kwargs) # type: ignore [assignment] # pylint: disable=protected-access
self._client._config.version = get_api_version(kwargs) # type: ignore [assignment]
self._configure_encryption(kwargs)

def _format_url(self, hostname: str) -> str:
Expand Down Expand Up @@ -3289,7 +3289,7 @@ def _get_container_client(self) -> "ContainerClient":
policies=self._pipeline._impl_policies # pylint: disable = protected-access
)
else:
_pipeline = self._pipeline # pylint: disable = protected-access
_pipeline = self._pipeline
return ContainerClient(
f"{self.scheme}://{self.primary_hostname}", container_name=self.container_name,
credential=self._raw_credential, api_version=self.api_version, _configuration=self._config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def _upload_blob_from_url_options(source_url: str, **kwargs: Any) -> Dict[str, A
'headers': headers,
}
options.update(kwargs)
if not overwrite and not _any_conditions(**options): # pylint: disable=protected-access
if not overwrite and not _any_conditions(**options):
options['modified_access_conditions'].if_none_match = '*'
return options

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def __init__(
self._query_str, credential = self._format_query_string(sas_token, credential)
super(BlobServiceClient, self).__init__(parsed_url, service='blob', credential=credential, **kwargs)
self._client = AzureBlobStorage(self.url, base_url=self.url, pipeline=self._pipeline)
self._client._config.version = get_api_version(kwargs) # type: ignore [assignment] # pylint: disable=protected-access
self._client._config.version = get_api_version(kwargs) # type: ignore [assignment]
self._configure_encryption(kwargs)

def _format_url(self, hostname):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ def set_container_metadata(
process_storage_error(error)

@distributed_trace
def _get_blob_service_client(self) -> "BlobServiceClient": # pylint: disable=client-method-missing-kwargs
def _get_blob_service_client(self) -> "BlobServiceClient":
"""Get a client to interact with the container's parent service account.
Defaults to current container's credentials.
Expand All @@ -648,7 +648,7 @@ def _get_blob_service_client(self) -> "BlobServiceClient": # pylint: disable=cl
policies=self._pipeline._impl_policies # pylint: disable = protected-access
)
else:
_pipeline = self._pipeline # pylint: disable = protected-access
_pipeline = self._pipeline
return BlobServiceClient(
f"{self.scheme}://{self.primary_hostname}",
credential=self._raw_credential, api_version=self.api_version, _configuration=self._config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def _generate_delete_blobs_options(
for blob in blobs:
if not isinstance(blob, str):
blob_name = blob.get('name')
options = _generic_delete_blob_options( # pylint: disable=protected-access
options = _generic_delete_blob_options(
snapshot=blob.get('snapshot'),
version_id=blob.get('version_id'),
delete_snapshots=delete_snapshots or blob.get('delete_snapshots'),
Expand All @@ -147,7 +147,7 @@ def _generate_delete_blobs_options(
)
else:
blob_name = blob
options = _generic_delete_blob_options( # pylint: disable=protected-access
options = _generic_delete_blob_options(
delete_snapshots=delete_snapshots,
if_modified_since=if_modified_since,
if_unmodified_since=if_unmodified_since,
Expand Down Expand Up @@ -199,11 +199,11 @@ def _generate_set_tiers_subrequest_options(
query_parameters['versionid'] = client._serialize.query("version_id", version_id, 'str') # pylint: disable=protected-access
if timeout is not None:
query_parameters['timeout'] = client._serialize.query("timeout", timeout, 'int', minimum=0) # pylint: disable=protected-access
query_parameters['comp'] = client._serialize.query("comp", comp, 'str') # pylint: disable=protected-access, specify-parameter-names-in-call
query_parameters['comp'] = client._serialize.query("comp", comp, 'str') # pylint: disable=protected-access

# Construct headers
header_parameters = {}
header_parameters['x-ms-access-tier'] = client._serialize.header("tier", tier, 'str') # pylint: disable=protected-access, specify-parameter-names-in-call
header_parameters['x-ms-access-tier'] = client._serialize.header("tier", tier, 'str') # pylint: disable=protected-access
if rehydrate_priority is not None:
header_parameters['x-ms-rehydrate-priority'] = client._serialize.header( # pylint: disable=protected-access
"rehydrate_priority", rehydrate_priority, 'str')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def service_properties_deserialize(generated: "StorageServiceProperties") -> Dic
'hour_metrics': Metrics._from_generated(generated.hour_metrics), # pylint: disable=protected-access
'minute_metrics': Metrics._from_generated(generated.minute_metrics), # pylint: disable=protected-access
'cors': cors_list,
'target_version': generated.default_service_version, # pylint: disable=protected-access
'target_version': generated.default_service_version,
'delete_retention_policy': RetentionPolicy._from_generated(generated.delete_retention_policy), # pylint: disable=protected-access
'static_website': StaticWebsite._from_generated(generated.static_website), # pylint: disable=protected-access
}
Expand Down Expand Up @@ -181,7 +181,7 @@ def get_blob_properties_from_generated_code(generated: "BlobItemInternal") -> Bl
blob.version_id = generated.version_id
blob.is_current_version = generated.is_current_version
blob.tag_count = generated.properties.tag_count
blob.tags = parse_tags(generated.blob_tags) # pylint: disable=protected-access
blob.tags = parse_tags(generated.blob_tags)
blob.object_replication_source_properties = deserialize_ors_policies(generated.object_replication_metadata)
blob.last_accessed_on = generated.properties.last_accessed_on
blob.immutability_policy = ImmutabilityPolicy._from_generated(generated) # pylint: disable=protected-access
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ def _generate_encryption_data_dict(
# We must pad the version to 8 bytes for AES Keywrap algorithms
to_wrap = _ENCRYPTION_PROTOCOL_V2.encode().ljust(8, b'\0') + cek
wrapped_cek = kek.wrap_key(to_wrap)
else:
raise ValueError("Invalid encryption version specified.")

# Build the encryption_data dict.
# Use OrderedDict to comply with Java's ordering requirement.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _build_item(self, item: Union[BlobItemInternal, BlobProperties]) -> BlobProp
if isinstance(item, BlobProperties):
return item
if isinstance(item, BlobItemInternal):
blob = get_blob_properties_from_generated_code(item) # pylint: disable=protected-access
blob = get_blob_properties_from_generated_code(item)
blob.container = self.container # type: ignore [assignment]
return blob
return item
Expand Down
7 changes: 4 additions & 3 deletions sdk/storage/azure-storage-blob/azure/storage/blob/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def __init__(self, **kwargs: Any) -> None:
)

@classmethod
def _from_generated(cls, generated): # pylint: disable=name-too-long
def _from_generated(cls, generated):
props = cls()
props.name = generated.name
props.last_modified = generated.properties.last_modified
Expand Down Expand Up @@ -934,7 +934,7 @@ def __init__(
delete_previous_version: bool = False,
tag: bool = False,
**kwargs: Any
) -> None: # pylint: disable=redefined-builtin
) -> None:
self.read = read
self.add = kwargs.pop('add', False)
self.create = kwargs.pop('create', False)
Expand Down Expand Up @@ -1443,7 +1443,8 @@ def __init__(self, **kwargs: Any) -> None:
self.snapshot = kwargs.get('x-ms-snapshot')
self.version_id = kwargs.get('x-ms-version-id')
self.is_current_version = kwargs.get('x-ms-is-current-version')
self.blob_type = BlobType(kwargs['x-ms-blob-type']) if kwargs.get('x-ms-blob-type') else None # type: ignore [assignment] # pylint: disable=line-too-long
self.blob_type = BlobType(kwargs['x-ms-blob-type']) if (
kwargs.get('x-ms-blob-type')) else None # type: ignore [assignment]
self.metadata = kwargs.get('metadata') # type: ignore [assignment]
self.encrypted_metadata = kwargs.get('encrypted_metadata')
self.last_modified = kwargs.get('Last-Modified') # type: ignore [assignment]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,7 @@ def __init__(
raise SchemaParseException(
f'Invalid record type: {record_type!r}.')

nested_names = []
if record_type in [RECORD, ERROR]:
avro_name = names.get_name(name=name, namespace=namespace)
nested_names = names.new_with_default_namespace(namespace=avro_name.namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@
}


class StorageAccountHostsMixin(object): # pylint: disable=too-many-instance-attributes
class StorageAccountHostsMixin(object):
_client: Any
def __init__(
self,
parsed_url: Any,
service: str,
credential: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "AsyncTokenCredential", TokenCredential]] = None, # pylint: disable=line-too-long
credential: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "AsyncTokenCredential", TokenCredential]] = None, # pylint: disable=line-too-long
**kwargs: Any
) -> None:
self._location_mode = kwargs.get("_location_mode", LocationMode.PRIMARY)
Expand Down Expand Up @@ -224,7 +224,7 @@ def _format_query_string(
return query_str.rstrip("?&"), credential

def _create_pipeline(
self, credential: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, TokenCredential]] = None, # pylint: disable=line-too-long
self, credential: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, TokenCredential]] = None, # pylint: disable=line-too-long
**kwargs: Any
) -> Tuple[StorageConfiguration, Pipeline]:
self._credential_policy: Any = None
Expand Down Expand Up @@ -308,7 +308,7 @@ def _batch_send(
enforce_https=False
)

Pipeline._prepare_multipart_mixed_request(request) # pylint: disable=protected-access
Pipeline._prepare_multipart_mixed_request(request) # pylint: disable=protected-access
body = serialize_batch_body(request.multipart_mixed_info[0], batch_id)
request.set_bytes_body(body)

Expand Down Expand Up @@ -358,13 +358,13 @@ def close(self):
def __enter__(self):
pass

def __exit__(self, *args): # pylint: disable=arguments-differ
def __exit__(self, *args):
pass


def _format_shared_key_credential(
account_name: str,
credential: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "AsyncTokenCredential", TokenCredential]] = None, # pylint: disable=line-too-long
credential: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "AsyncTokenCredential", TokenCredential]] = None # pylint: disable=line-too-long
) -> Any:
if isinstance(credential, str):
if not account_name:
Expand All @@ -383,9 +383,9 @@ def _format_shared_key_credential(

def parse_connection_str(
conn_str: str,
credential: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, TokenCredential]], # pylint: disable=line-too-long
credential: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, TokenCredential]],
service: str
) -> Tuple[str, Optional[str], Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, TokenCredential]]]: # pylint: disable=line-too-long
) -> Tuple[str, Optional[str], Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, TokenCredential]]]: # pylint: disable=line-too-long
conn_str = conn_str.rstrip(";")
conn_settings_list = [s.split("=", 1) for s in conn_str.split(";")]
if any(len(tup) != 2 for tup in conn_settings_list):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ async def _batch_send(

def parse_connection_str(
conn_str: str,
credential: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, AsyncTokenCredential]], # pylint: disable=line-too-long
credential: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, AsyncTokenCredential]],
service: str
) -> Tuple[str, Optional[str], Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, AsyncTokenCredential]]]: # pylint: disable=line-too-long
conn_str = conn_str.rstrip(";")
Expand Down Expand Up @@ -276,5 +276,5 @@ async def close(self):
async def __aenter__(self):
pass

async def __aexit__(self, *args): # pylint: disable=arguments-differ
async def __aexit__(self, *args):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def from_string(cls, string):
res_object = 'o' in string

parsed = cls(res_service, res_container, res_object)
parsed._str = string # pylint: disable = protected-access
parsed._str = string
return parsed


Expand Down Expand Up @@ -495,7 +495,7 @@ def from_string(cls, string):
res_file = 'f' in string

parsed = cls(blob=res_blob, queue=res_queue, fileshare=res_file)
parsed._str = string # pylint: disable = protected-access
parsed._str = string
return parsed


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def retry_hook(settings, **kwargs):
# respect the Retry-After header, whether this header is present, and
# whether the returned status code is on the list of status codes to
# be retried upon on the presence of the aforementioned header)
def is_retry(response, mode): # pylint: disable=too-many-return-statements
def is_retry(response, mode):
status = response.http_response.status_code
if 300 <= status < 500:
# An exception occurred, but in most cases it was expected. Examples could
Expand Down Expand Up @@ -267,7 +267,7 @@ def on_response(self, request: "PipelineRequest", response: "PipelineResponse")

class StorageRequestHook(SansIOHTTPPolicy):

def __init__(self, **kwargs): # pylint: disable=unused-argument
def __init__(self, **kwargs):
self._request_callback = kwargs.get('raw_request_hook')
super(StorageRequestHook, self).__init__()

Expand All @@ -279,7 +279,7 @@ def on_request(self, request: "PipelineRequest") -> None:

class StorageResponseHook(HTTPPolicy):

def __init__(self, **kwargs): # pylint: disable=unused-argument
def __init__(self, **kwargs):
self._response_callback = kwargs.get('raw_response_hook')
super(StorageResponseHook, self).__init__()

Expand Down Expand Up @@ -450,7 +450,7 @@ def get_backoff_time(self, settings: Dict[str, Any]) -> float: # pylint: disabl
""" Formula for computing the current backoff.
Should be calculated by child class.
:param Dict[str, Any]] settings: The configurable values pertaining to the backoff time.
:param Dict[str, Any] settings: The configurable values pertaining to the backoff time.
:returns: The backoff time.
:rtype: float
"""
Expand All @@ -470,12 +470,11 @@ def increment(
) -> bool:
"""Increment the retry counters.
:param Dict[str, Any]] settings: The configurable values pertaining to the increment operation.
:param Dict[str, Any] settings: The configurable values pertaining to the increment operation.
:param PipelineRequest request: A pipeline request object.
:param Optional[PipelineResponse] response: A pipeline response object.
:param error: An error encountered during the request, or
:param Optional[AzureError] error: An error encountered during the request, or
None if the response was received successfully.
:type error: Optional[AzureError]
:returns: Whether the retry attempts are exhausted.
:rtype: bool
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async def is_checksum_retry(response):

class AsyncStorageResponseHook(AsyncHTTPPolicy):

def __init__(self, **kwargs): # pylint: disable=unused-argument
def __init__(self, **kwargs):
self._response_callback = kwargs.get('raw_response_hook')
super(AsyncStorageResponseHook, self).__init__()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def _upload_substream_block(self, index, block_stream):
return block_id


class PageBlobChunkUploader(_ChunkUploader): # pylint: disable=abstract-method
class PageBlobChunkUploader(_ChunkUploader):

def _is_chunk_empty(self, chunk_data):
# read until non-zero byte is encountered
Expand Down Expand Up @@ -312,7 +312,7 @@ def _upload_substream_block(self, index, block_stream):
pass


class AppendBlobChunkUploader(_ChunkUploader): # pylint: disable=abstract-method
class AppendBlobChunkUploader(_ChunkUploader):

def __init__(self, *args, **kwargs):
super(AppendBlobChunkUploader, self).__init__(*args, **kwargs)
Expand Down Expand Up @@ -345,7 +345,7 @@ def _upload_substream_block(self, index, block_stream):
pass


class DataLakeFileChunkUploader(_ChunkUploader): # pylint: disable=abstract-method
class DataLakeFileChunkUploader(_ChunkUploader):

def _upload_chunk(self, chunk_offset, chunk_data):
# avoid uploading the empty pages
Expand Down Expand Up @@ -377,7 +377,7 @@ def _upload_substream_block(self, index, block_stream):
block_stream.close()


class FileChunkUploader(_ChunkUploader): # pylint: disable=abstract-method
class FileChunkUploader(_ChunkUploader):

def _upload_chunk(self, chunk_offset, chunk_data):
length = len(chunk_data)
Expand Down
Loading

0 comments on commit 9e01adc

Please sign in to comment.