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 Queue] pylint + mypy pass #6187

Merged
merged 1 commit into from
Jul 1, 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
Expand Up @@ -12,8 +12,8 @@
try:
from urllib.parse import urlparse, unquote
except ImportError:
from urlparse import urlparse
from urllib2 import unquote
from urlparse import urlparse # type: ignore
from urllib2 import unquote # type: ignore

from azure.core.exceptions import ClientAuthenticationError
from azure.core.pipeline.policies import SansIOHTTPPolicy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
if sys.version_info >= (3, 5):
# the timeout to connect is 20 seconds, and the read timeout is 2000 seconds
# the 2000 seconds was calculated with: 100MB (max block size)/ 50KB/s (an arbitrarily chosen minimum upload speed)
DEFAULT_SOCKET_TIMEOUT = (20, 2000)
DEFAULT_SOCKET_TIMEOUT = (20, 2000) # type: ignore

STORAGE_OAUTH_SCOPE = "https://storage.azure.com/.default"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def __str__(self):
('f' if self.file else ''))


Services.BLOB = Services(blob=True)
Services.QUEUE = Services(queue=True)
Services.TABLE = Services(table=True)
Services.FILE = Services(file=True)
Services.BLOB = Services(blob=True) # type: ignore
Services.QUEUE = Services(queue=True) # type: ignore
Services.TABLE = Services(table=True) # type: ignore
Services.FILE = Services(file=True) # type: ignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import uuid
import types
import platform
from typing import Any, TYPE_CHECKING
from wsgiref.handlers import format_date_time
try:
from urllib.parse import (
Expand All @@ -23,8 +24,8 @@
urlencode,
)
except ImportError:
from urllib import urlencode
from urlparse import (
from urllib import urlencode # type: ignore
from urlparse import ( # type: ignore
urlparse,
parse_qsl,
urlunparse,
Expand All @@ -42,13 +43,14 @@
from .models import LocationMode

try:
_unicode_type = unicode
_unicode_type = unicode # type: ignore
except NameError:
_unicode_type = str


_LOGGER = logging.getLogger(__name__)

if TYPE_CHECKING:
from azure.core.pipeline import PipelineRequest, PipelineResponse

def encode_base64(data):
if isinstance(data, _unicode_type):
Expand Down Expand Up @@ -274,7 +276,7 @@ def __init__(self, **kwargs): # pylint: disable=unused-argument
super(StorageRequestHook, self).__init__()

def on_request(self, request, **kwargs):
# type: (PipelineRequest) -> PipelineResponse
# type: (PipelineRequest, **Any) -> PipelineResponse
request_callback = request.context.options.pop('raw_request_hook', self._request_callback)
if request_callback:
request_callback(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# --------------------------------------------------------------------------

from typing import ( # pylint: disable=unused-import
Union, Optional, Any, Iterable, Dict, List, Type,
Union, Optional, Any, Iterable, Dict, List, Type, Tuple,
TYPE_CHECKING
)
import base64
Expand All @@ -18,8 +18,8 @@
try:
from urllib.parse import quote, unquote, parse_qs
except ImportError:
from urlparse import parse_qs
from urllib2 import quote, unquote
from urlparse import parse_qs # type: ignore
from urllib2 import quote, unquote # type: ignore

import six
import isodate
Expand Down Expand Up @@ -118,7 +118,7 @@ def to_list():
class StorageAccountHostsMixin(object):

def __init__(
self, parsed_url, # type: str
self, parsed_url, # type: Any
service, # type: str
credential=None, # type: Optional[Any]
**kwargs # type: Any
Expand Down Expand Up @@ -485,7 +485,7 @@ def create_configuration(**kwargs):


def create_pipeline(credential, **kwargs):
# type: (Configuration, Optional[HTTPPolicy], **Any) -> Tuple[Configuration, Pipeline]
# type: (Any, **Any) -> Tuple[Configuration, Pipeline]
credential_policy = None
if hasattr(credential, 'get_token'):
credential_policy = BearerTokenCredentialPolicy(credential, STORAGE_OAUTH_SCOPE)
Expand Down
12 changes: 5 additions & 7 deletions sdk/storage/azure-storage-queue/azure/storage/queue/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# pylint: disable=too-few-public-methods, too-many-instance-attributes
# pylint: disable=super-init-not-called

from typing import List # pylint: disable=unused-import
from azure.core.paging import Paged

from ._shared.utils import (
return_context_and_deserialized,
process_storage_error)
Expand Down Expand Up @@ -232,7 +232,6 @@ def __init__(self, command, results_per_page=None):
self.results_per_page = results_per_page

def _advance_page(self):
# type: () -> List[Model]
"""Force moving the cursor to the next azure call.

This method is for advanced usage, iterator protocol is prefered.
Expand Down Expand Up @@ -297,7 +296,6 @@ def __init__(self, command, prefix=None, results_per_page=None, marker=None):
self.location_mode = None

def _advance_page(self):
# type: () -> List[Model]
"""Force moving the cursor to the next azure call.

This method is for advanced usage, iterator protocol is prefered.
Expand Down Expand Up @@ -375,7 +373,7 @@ def __str__(self):
('p' if self.process else ''))


QueuePermissions.READ = QueuePermissions(read=True)
QueuePermissions.ADD = QueuePermissions(add=True)
QueuePermissions.UPDATE = QueuePermissions(update=True)
QueuePermissions.PROCESS = QueuePermissions(process=True)
QueuePermissions.READ = QueuePermissions(read=True) # type: ignore
QueuePermissions.ADD = QueuePermissions(add=True) # type: ignore
QueuePermissions.UPDATE = QueuePermissions(update=True) # type: ignore
QueuePermissions.PROCESS = QueuePermissions(process=True) # type: ignore
43 changes: 25 additions & 18 deletions sdk/storage/azure-storage-queue/azure/storage/queue/queue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
try:
from urllib.parse import urlparse, quote, unquote
except ImportError:
from urlparse import urlparse
from urllib2 import quote, unquote
from urlparse import urlparse # type: ignore
from urllib2 import quote, unquote # type: ignore

import six

Expand All @@ -39,8 +39,9 @@
from .models import QueueMessage, AccessPolicy, MessagesPaged

if TYPE_CHECKING:
from datetime import datetime
from azure.core.pipeline.policies import HTTPPolicy
from .models import QueuePermissions
from .models import QueuePermissions, QueueProperties


class QueueClient(StorageAccountHostsMixin):
Expand All @@ -67,7 +68,7 @@ class QueueClient(StorageAccountHostsMixin):
"""
def __init__(
self, queue_url, # type: str
queue=None, # type: Optional[str]
queue=None, # type: Optional[Union[QueueProperties, str]]
credential=None, # type: Optional[Any]
**kwargs # type: Any
):
Expand All @@ -90,7 +91,7 @@ def __init__(
if not sas_token and not credential:
raise ValueError("You need to provide either a SAS token or an account key to authenticate.")
try:
self.queue_name = queue.name
self.queue_name = queue.name # type: ignore
except AttributeError:
self.queue_name = queue or unquote(path_queue)
self._query_str, credential = self._format_query_string(sas_token, credential)
Expand Down Expand Up @@ -146,7 +147,7 @@ def from_connection_string(
conn_str, credential, 'queue')
if 'secondary_hostname' not in kwargs:
kwargs['secondary_hostname'] = secondary
return cls(account_url, queue=queue, credential=credential, **kwargs)
return cls(account_url, queue=queue, credential=credential, **kwargs) # type: ignore

def generate_shared_access_signature(
self, permission=None, # type: Optional[Union[QueuePermissions, str]]
Expand Down Expand Up @@ -244,9 +245,9 @@ def create_queue(self, metadata=None, timeout=None, **kwargs):
:caption: Create a queue.
"""
headers = kwargs.pop('headers', {})
headers.update(add_metadata_headers(metadata))
headers.update(add_metadata_headers(metadata)) # type: ignore
try:
return self._client.queue.create(
return self._client.queue.create( # type: ignore
metadata=metadata,
timeout=timeout,
headers=headers,
Expand Down Expand Up @@ -311,7 +312,7 @@ def get_queue_properties(self, timeout=None, **kwargs):
except StorageErrorException as error:
process_storage_error(error)
response.name = self.queue_name
return response
return response # type: ignore

def set_queue_metadata(self, metadata=None, timeout=None, **kwargs):
# type: (Optional[Dict[str, Any]], Optional[int], Optional[Any]) -> None
Expand All @@ -335,9 +336,9 @@ def set_queue_metadata(self, metadata=None, timeout=None, **kwargs):
:caption: Set metadata on the queue.
"""
headers = kwargs.pop('headers', {})
headers.update(add_metadata_headers(metadata))
headers.update(add_metadata_headers(metadata)) # type: ignore
try:
return self._client.queue.set_metadata(
return self._client.queue.set_metadata( # type: ignore
timeout=timeout,
headers=headers,
cls=return_response_headers,
Expand Down Expand Up @@ -407,7 +408,7 @@ def set_queue_access_policy(self, signed_identifiers=None, timeout=None, **kwarg
value.start = serialize_iso(value.start)
value.expiry = serialize_iso(value.expiry)
identifiers.append(SignedIdentifier(id=key, access_policy=value))
signed_identifiers = identifiers
signed_identifiers = identifiers # type: ignore
try:
self._client.queue.set_access_policy(
queue_acl=signed_identifiers or None,
Expand All @@ -416,8 +417,14 @@ def set_queue_access_policy(self, signed_identifiers=None, timeout=None, **kwarg
except StorageErrorException as error:
process_storage_error(error)

def enqueue_message(self, content, visibility_timeout=None, time_to_live=None, timeout=None, **kwargs):
# type: (Any, Optional[int], Optional[int], Optional[int], Optional[Any]) -> QueueMessage
def enqueue_message( # type: ignore
self, content, # type: Any
visibility_timeout=None, # type: Optional[int]
time_to_live=None, # type: Optional[int]
timeout=None, # type: Optional[int]
**kwargs # type: Optional[Any]
):
# type: (...) -> QueueMessage
"""Adds a new message to the back of the message queue.

The visibility timeout specifies the time that the message will be
Expand Down Expand Up @@ -486,7 +493,7 @@ def enqueue_message(self, content, visibility_timeout=None, time_to_live=None, t
except StorageErrorException as error:
process_storage_error(error)

def receive_messages(self, messages_per_page=None, visibility_timeout=None, timeout=None, **kwargs):
def receive_messages(self, messages_per_page=None, visibility_timeout=None, timeout=None, **kwargs): # type: ignore
# type: (Optional[int], Optional[int], Optional[int], Optional[Any]) -> QueueMessage
"""Removes one or more messages from the front of the queue.

Expand Down Expand Up @@ -543,7 +550,7 @@ def receive_messages(self, messages_per_page=None, visibility_timeout=None, time
except StorageErrorException as error:
process_storage_error(error)

def update_message(self, message, visibility_timeout=None, pop_receipt=None,
def update_message(self, message, visibility_timeout=None, pop_receipt=None, # type: ignore
content=None, timeout=None, **kwargs):
# type: (Any, int, Optional[str], Optional[Any], Optional[int], Any) -> QueueMessage
"""Updates the visibility timeout of a message. You can also use this
Expand Down Expand Up @@ -615,7 +622,7 @@ def update_message(self, message, visibility_timeout=None, pop_receipt=None,
message_text = self._config.message_encode_policy(message_text)
updated = GenQueueMessage(message_text=message_text)
else:
updated = None
updated = None # type: ignore
try:
response = self._client.message_id.update(
queue_message=updated,
Expand All @@ -636,7 +643,7 @@ def update_message(self, message, visibility_timeout=None, pop_receipt=None,
except StorageErrorException as error:
process_storage_error(error)

def peek_messages(self, max_messages=None, timeout=None, **kwargs):
def peek_messages(self, max_messages=None, timeout=None, **kwargs): # type: ignore
# type: (Optional[int], Optional[int], Optional[Any]) -> List[QueueMessage]
"""Retrieves one or more messages from the front of the queue, but does
not alter the visibility of the message.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
from urlparse import urlparse # type: ignore

from ._shared.shared_access_signature import SharedAccessSignature
from ._shared.models import LocationMode, Services
Expand All @@ -27,8 +27,16 @@
from .queue_client import QueueClient

if TYPE_CHECKING:
from datetime import datetime
from azure.core import Configuration
from azure.core.pipeline.policies import HTTPPolicy
from ._shared.models import AccountPermissions, ResourceTypes
from .models import (
QueueProperties,
Logging,
Metrics,
CorsRule
)


class QueueServiceClient(StorageAccountHostsMixin):
Expand Down Expand Up @@ -164,9 +172,9 @@ def generate_shared_access_signature(

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

def get_service_stats(self, timeout=None, **kwargs):
def get_service_stats(self, timeout=None, **kwargs): # type: ignore
# type: (Optional[int], Optional[Any]) -> Dict[str, Any]
"""Retrieves statistics related to replication for the Queue service.

Expand All @@ -192,12 +200,12 @@ def get_service_stats(self, timeout=None, **kwargs):
:rtype: ~azure.storage.queue._generated.models._models.StorageServiceStats
"""
try:
return self._client.service.get_statistics(
return self._client.service.get_statistics( # type: ignore
timeout=timeout, use_location=LocationMode.SECONDARY, **kwargs)
except StorageErrorException as error:
process_storage_error(error)

def get_service_properties(self, timeout=None, **kwargs):
def get_service_properties(self, timeout=None, **kwargs): # type: ignore
# type: (Optional[int], Optional[Any]) -> Dict[str, Any]
"""Gets the properties of a storage account's Queue service, including
Azure Storage Analytics.
Expand All @@ -215,11 +223,11 @@ def get_service_properties(self, timeout=None, **kwargs):
:caption: Getting queue service properties.
"""
try:
return self._client.service.get_properties(timeout=timeout, **kwargs)
return self._client.service.get_properties(timeout=timeout, **kwargs) # type: ignore
except StorageErrorException as error:
process_storage_error(error)

def set_service_properties(
def set_service_properties( # type: ignore
self, logging=None, # type: Optional[Logging]
hour_metrics=None, # type: Optional[Metrics]
minute_metrics=None, # type: Optional[Metrics]
Expand Down Expand Up @@ -269,7 +277,7 @@ def set_service_properties(
cors=cors
)
try:
return self._client.service.set_properties(props, timeout=timeout, **kwargs)
return self._client.service.set_properties(props, timeout=timeout, **kwargs) # type: ignore
except StorageErrorException as error:
process_storage_error(error)

Expand Down Expand Up @@ -388,8 +396,8 @@ def delete_queue(
:dedent: 12
:caption: Delete a queue in the service.
"""
queue = self.get_queue_client(queue)
queue.delete_queue(timeout=timeout, **kwargs)
queue_client = self.get_queue_client(queue)
queue_client.delete_queue(timeout=timeout, **kwargs)

def get_queue_client(self, queue, **kwargs):
# type: (Union[QueueProperties, str], Optional[Any]) -> QueueClient
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/azure-storage-queue/mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ignore_missing_imports = True

# Per-module options:

[mypy-azure.storage.blob._generated.*]
[mypy-azure.storage.queue._generated.*]
ignore_errors = True

[mypy-azure.core.*]
Expand Down