Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[storage] make storage pylint-clean #6929

Merged
merged 2 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

from azure.storage.blob._shared import sign_string, url_quote
from azure.storage.blob._shared.constants import X_MS_VERSION
from azure.storage.blob._shared.shared_access_signature import SharedAccessSignature, _SharedAccessHelper, \
Expand Down Expand Up @@ -187,8 +193,6 @@ def generate_container(self, container_name, permission=None, expiry=None,


class _BlobSharedAccessHelper(_SharedAccessHelper):
def __init__(self):
super(_BlobSharedAccessHelper, self).__init__()

def add_timestamp(self, timestamp):
self._add_query(BlobQueryStringConstants.SIGNED_TIMESTAMP, timestamp)
Expand Down Expand Up @@ -254,4 +258,4 @@ def get_token(self):
# this is to avoid having two snapshot ids in the query parameters when the user appends the snapshot timestamp
exclude = [BlobQueryStringConstants.SIGNED_TIMESTAMP]
return '&'.join(['{0}={1}'.format(n, url_quote(v))
for n, v in self.query_dict.items() if v is not None and n not in exclude])
for n, v in self.query_dict.items() if v is not None and n not in exclude])
Original file line number Diff line number Diff line change
Expand Up @@ -1481,9 +1481,9 @@ async def upload_page( # type: ignore
:rtype: dict(str, Any)
"""
options = self._upload_page_options(
page,
start_range,
end_range,
page=page,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity...what is the error pylint throws here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify parameter names when making calls with more than 2 positional parameters.

start_range=start_range,
end_range=end_range,
length=length,
validate_content=validate_content,
**kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ async def get_service_stats(self, timeout=None, **kwargs): # type: ignore

@distributed_trace_async
async def get_service_properties(self, timeout=None, **kwargs):
# type(Optional[int]) -> Dict[str, Any]
# type: (Optional[int], Any) -> Dict[str, Any]
"""Gets the properties of a storage account's Blob service, including
Azure Storage Analytics.

Expand Down Expand Up @@ -472,7 +472,8 @@ def get_blob_client(
:type blob: str or ~azure.storage.blob.models.BlobProperties
:param snapshot:
The optional blob snapshot on which to operate. This can either be the ID of the snapshot,
or a dictionary output returned by :func:`~azure.storage.blob.aio.blob_client_async.BlobClient.create_snapshot()`.
or a dictionary output returned by
:func:`~azure.storage.blob.aio.blob_client_async.BlobClient.create_snapshot()`.
:type snapshot: str or dict(str, Any)
:returns: A BlobClient.
:rtype: ~azure.storage.blob.aio.blob_client_async.BlobClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,8 @@ async def set_container_access_policy(
public_access=None, # type: Optional[Union[str, PublicAccess]]
lease=None, # type: Optional[Union[str, LeaseClient]]
timeout=None, # type: Optional[int]
**kwargs
):
**kwargs # type: Any
): # type: (...) -> Dict[str, Union[str, datetime]]
"""Sets the permissions for the specified container or stored access
policies that may be used with Shared Access Signatures. The permissions
indicate whether blobs in a container may be accessed publicly.
Expand Down
12 changes: 6 additions & 6 deletions sdk/storage/azure-storage-blob/azure/storage/blob/blob_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ def __init__(
self.snapshot = blob.snapshot # type: ignore
except AttributeError:
self.blob_name = blob or unquote(path_blob)
self._query_str, credential = self._format_query_string(sas_token, credential, self.snapshot)
super(BlobClient, self).__init__(parsed_url, 'blob', credential, **kwargs)
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, pipeline=self._pipeline)

def _format_url(self, hostname):
Expand All @@ -185,7 +185,7 @@ def from_connection_string(
snapshot=None, # type: Optional[str]
credential=None, # type: Optional[Any]
**kwargs # type: Any
):
): # type: (...) -> BlobClient
"""
Create BlobClient from a Connection String.

Expand Down Expand Up @@ -2257,9 +2257,9 @@ def upload_page( # type: ignore
:rtype: dict(str, Any)
"""
options = self._upload_page_options(
page,
start_range,
end_range,
page=page,
start_range=start_range,
end_range=end_range,
length=length,
validate_content=validate_content,
**kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __init__(

_, sas_token = parse_query(parsed_url.query)
self._query_str, credential = self._format_query_string(sas_token, credential)
super(BlobServiceClient, self).__init__(parsed_url, 'blob', credential, **kwargs)
super(BlobServiceClient, self).__init__(parsed_url, service='blob', credential=credential, **kwargs)
self._client = AzureBlobStorage(self.url, pipeline=self._pipeline)

def _format_url(self, hostname):
Expand All @@ -127,7 +127,7 @@ def from_connection_string(
cls, conn_str, # type: str
credential=None, # type: Optional[Any]
**kwargs # type: Any
):
): # type: (...) -> BlobServiceClient
"""Create BlobServiceClient from a Connection String.

:param str conn_str:
Expand Down Expand Up @@ -159,7 +159,7 @@ def generate_shared_access_signature(
start=None, # type: Optional[Union[datetime, str]]
ip=None, # type: Optional[str]
protocol=None # type: Optional[str]
):
): # type: (...) -> str
"""Generates a shared access signature for the blob service.

Use the returned signature with the credential parameter of any BlobServiceClient,
Expand Down Expand Up @@ -214,7 +214,14 @@ def generate_shared_access_signature(

sas = SharedAccessSignature(self.credential.account_name, self.credential.account_key)
return sas.generate_account(
Services.BLOB, resource_types, permission, expiry, start=start, ip=ip, protocol=protocol) # type: ignore
services=Services.BLOB,
resource_types=resource_types,
permission=permission,
expiry=expiry,
start=start,
ip=ip,
protocol=protocol
) # type: ignore

@distributed_trace
def get_account_information(self, **kwargs): # type: ignore
Expand Down Expand Up @@ -282,7 +289,7 @@ def get_service_stats(self, timeout=None, **kwargs): # type: ignore

@distributed_trace
def get_service_properties(self, timeout=None, **kwargs):
# type(Optional[int]) -> Dict[str, Any]
# type: (Optional[int], Any) -> Dict[str, Any]
"""Gets the properties of a storage account's Blob service, including
Azure Storage Analytics.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
from urlparse import urlparse # type: ignore
from urllib2 import quote, unquote # type: ignore

import six

from azure.core.paging import ItemPaged
from azure.core.tracing.decorator import distributed_trace

import six

from ._shared.base_client import StorageAccountHostsMixin, parse_connection_str, parse_query
from ._shared.request_handlers import add_metadata_headers, serialize_iso
from ._shared.response_handlers import (
Expand Down Expand Up @@ -133,7 +133,7 @@ def __init__(
except AttributeError:
self.container_name = container or unquote(path_container) # type: ignore
self._query_str, credential = self._format_query_string(sas_token, credential)
super(ContainerClient, self).__init__(parsed_url, 'blob', credential, **kwargs)
super(ContainerClient, self).__init__(parsed_url, service='blob', credential=credential, **kwargs)
self._client = AzureBlobStorage(self.url, pipeline=self._pipeline)

def _format_url(self, hostname):
Expand All @@ -152,7 +152,7 @@ def from_connection_string(
container, # type: Union[str, ContainerProperties]
credential=None, # type: Optional[Any]
**kwargs # type: Any
):
): # type: (...) -> ContainerClient
"""Create ContainerClient from a Connection String.

:param str conn_str:
Expand Down Expand Up @@ -581,7 +581,7 @@ def set_container_access_policy(
lease=None, # type: Optional[Union[str, LeaseClient]]
timeout=None, # type: Optional[int]
**kwargs
):
): # type: (...) -> Dict[str, Union[str, datetime]]
"""Sets the permissions for the specified container or stored access
policies that may be used with Shared Access Signatures. The permissions
indicate whether blobs in a container may be accessed publicly.
Expand Down
4 changes: 3 additions & 1 deletion sdk/storage/azure-storage-blob/azure/storage/blob/lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ class LeaseClient(object):
A string representing the lease ID of an existing lease. This value does not
need to be specified in order to acquire a new lease, or break one.
"""
def __init__(self, client, lease_id=None):
def __init__(
self, client, lease_id=None
): # pylint: disable=missing-client-constructor-parameter-credential,missing-client-constructor-parameter-kwargs
# type: (Union[BlobClient, ContainerClient], Optional[str]) -> None
self.id = lease_id or str(uuid.uuid4())
self.last_modified = None
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

from azure.storage.file._shared import sign_string
from azure.storage.file._shared.constants import X_MS_VERSION
from azure.storage.file._shared.shared_access_signature import SharedAccessSignature, _str, _SharedAccessHelper, \
Expand Down Expand Up @@ -179,8 +185,6 @@ def generate_share(self, share_name, permission=None, expiry=None,


class _FileSharedAccessHelper(_SharedAccessHelper):
def __init__(self):
super(_FileSharedAccessHelper, self).__init__()

def add_resource_signature(self, account_name, account_key, path):
def get_value_to_append(query):
Expand Down Expand Up @@ -214,4 +218,4 @@ def get_value_to_append(query):
string_to_sign = string_to_sign[:-1]

self._add_query(QueryStringConstants.SIGNED_SIGNATURE,
sign_string(account_key, string_to_sign))
sign_string(account_key, string_to_sign))
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def __init__( # type: ignore
self._loop = loop

def get_file_client(self, file_name, **kwargs):
# type: (str, Any) -> FileClient
"""Get a client to interact with a specific file.

The file need not already exist.
Expand All @@ -113,6 +114,7 @@ def get_file_client(self, file_name, **kwargs):
_location_mode=self._location_mode, loop=self._loop, **kwargs)

def get_subdirectory_client(self, directory_name, **kwargs):
# type: (str, Any) -> DirectoryClient
"""Get a client to interact with a specific subdirectory.

The subdirectory need not already exist.
Expand Down Expand Up @@ -227,7 +229,8 @@ def list_directories_and_files(self, name_starts_with=None, timeout=None, **kwar
page_iterator_class=DirectoryPropertiesPaged)

@distributed_trace
def list_handles(self, recursive=False, timeout=None, **kwargs) -> AsyncItemPaged:
def list_handles(self, recursive=False, timeout=None, **kwargs):
# type: (bool, Optional[int], Any) -> AsyncItemPaged
"""Lists opened handles on a directory or a file under the directory.

:param bool recursive:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,8 @@ async def resize_file(self, size, timeout=None, **kwargs): # type: ignore
process_storage_error(error)

@distributed_trace
def list_handles(self, timeout=None, **kwargs) -> AsyncItemPaged:
def list_handles(self, timeout=None, **kwargs):
# type: (Optional[int], Any) -> AsyncItemPaged
"""Lists handles for file.

:param int timeout:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __init__(

@distributed_trace_async
async def get_service_properties(self, timeout=None, **kwargs):
# type(Optional[int]) -> Dict[str, Any]
# type: (Optional[int], Any) -> Dict[str, Any]
"""Gets the properties of a storage account's File service, including
Azure Storage Analytics.

Expand Down Expand Up @@ -166,8 +166,8 @@ def list_shares(
include_metadata=False, # type: Optional[bool]
include_snapshots=False, # type: Optional[bool]
timeout=None, # type: Optional[int]
**kwargs
) -> AsyncItemPaged:
**kwargs # type: Any
): # type: (...) -> AsyncItemPaged
"""Returns auto-paging iterable of dict-like ShareProperties under the specified account.
The generator will lazily follow the continuation tokens returned by
the service and stop when all shares have been returned.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def __init__( # type: ignore
self._loop = loop

def get_directory_client(self, directory_path=None):
# type: (Optional[str]) -> DirectoryClient
"""Get a client to interact with the specified directory.
The directory need not already exist.

Expand All @@ -103,6 +104,7 @@ def get_directory_client(self, directory_path=None):
_location_mode=self._location_mode, loop=self._loop)

def get_file_client(self, file_path):
# type: (str) -> FileClient
"""Get a client to interact with the specified file.
The file need not already exist.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def __init__( # type: ignore

self._query_str, credential = self._format_query_string(
sas_token, credential, share_snapshot=self.snapshot)
super(DirectoryClient, self).__init__(parsed_url, 'file', credential, **kwargs)
super(DirectoryClient, self).__init__(parsed_url, service='file', credential=credential, **kwargs)
self._client = AzureFileStorage(version=VERSION, url=self.url, pipeline=self._pipeline)

def _format_url(self, hostname):
Expand Down Expand Up @@ -168,6 +168,7 @@ def from_connection_string(
account_url, share=share, directory_path=directory_path, credential=credential, **kwargs)

def get_file_client(self, file_name, **kwargs):
# type: (str, Any) -> FileClient
"""Get a client to interact with a specific file.

The file need not already exist.
Expand All @@ -185,6 +186,7 @@ def get_file_client(self, file_name, **kwargs):
_location_mode=self._location_mode, **kwargs)

def get_subdirectory_client(self, directory_name, **kwargs):
# type: (str, Any) -> DirectoryClient
"""Get a client to interact with a specific subdirectory.

The subdirectory need not already exist.
Expand Down Expand Up @@ -300,6 +302,7 @@ def list_directories_and_files(self, name_starts_with=None, timeout=None, **kwar

@distributed_trace
def list_handles(self, recursive=False, timeout=None, **kwargs):
# type: (bool, Optional[int], Any) -> ItemPaged
"""Lists opened handles on a directory or a file under the directory.

:param bool recursive:
Expand Down
12 changes: 6 additions & 6 deletions sdk/storage/azure-storage-file/azure/storage/file/file_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def __init__( # type: ignore
self.directory_path = "/".join(self.file_path[:-1])
self._query_str, credential = self._format_query_string(
sas_token, credential, share_snapshot=self.snapshot)
super(FileClient, self).__init__(parsed_url, 'file', credential, **kwargs)
super(FileClient, self).__init__(parsed_url, service='file', credential=credential, **kwargs)
self._client = AzureFileStorage(version=VERSION, url=self.url, pipeline=self._pipeline)

def _format_url(self, hostname):
Expand Down Expand Up @@ -302,11 +302,11 @@ def generate_shared_access_signature(
else:
file_path = None # type: ignore
return sas.generate_file( # type: ignore
self.share_name,
file_path,
self.file_name,
permission,
expiry,
share_name=self.share_name,
directory_name=file_path,
file_name=self.file_name,
permission=permission,
expiry=expiry,
start=start,
policy_id=policy_id,
ip=ip,
Expand Down
Loading