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

updating pylint statements #16362

Merged
5 commits merged into from
Jan 27, 2021
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 @@ -49,7 +49,7 @@ class AzureSigningError(ClientAuthenticationError):
class SharedKeyCredentialPolicy(SansIOHTTPPolicy):
def __init__(
self, account_name, account_key, is_emulated=False
): # pylint: disable=super-init-not-called
):
self.account_name = account_name
self.account_key = account_key
self.is_emulated = is_emulated
Expand Down
39 changes: 21 additions & 18 deletions sdk/tables/azure-data-tables/azure/data/tables/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,8 @@
# license information.
# --------------------------------------------------------------------------

from typing import ( # pylint: disable=unused-import
Union,
Optional,
Any,
Iterable,
Dict,
List,
Type,
Tuple,
TYPE_CHECKING,
)
from typing import TYPE_CHECKING

import logging
from uuid import uuid4, UUID
from datetime import datetime
Expand Down Expand Up @@ -65,6 +56,18 @@
from ._models import BatchErrorException
from ._sdk_moniker import SDK_MONIKER

if TYPE_CHECKING:
from typing import ( # pylint: disable=ungrouped-imports
Union,
Optional,
Any,
Iterable,
Dict,
List,
Type,
Tuple,
)

_LOGGER = logging.getLogger(__name__)
_SERVICE_PARAMS = {
"blob": {"primary": "BlobEndpoint", "secondary": "BlobSecondaryEndpoint"},
Expand All @@ -75,7 +78,7 @@
}


class StorageAccountHostsMixin(object): # pylint: disable=too-many-instance-attributes
class StorageAccountHostsMixin(object):
def __init__(
self,
parsed_url, # type: Any
Expand Down Expand Up @@ -261,7 +264,7 @@ def _configure_credential(self, credential):
elif credential is not None:
raise TypeError("Unsupported credential: {}".format(credential))

def _batch_send( # pylint: disable=inconsistent-return-statements
def _batch_send(
self,
entities, # type: List[TableEntity]
*reqs, # type: List[HttpRequest]
Expand Down Expand Up @@ -292,7 +295,7 @@ def _batch_send( # pylint: disable=inconsistent-return-statements
boundary="batch_{}".format(uuid4()),
)

pipeline_response = self._client._client._pipeline.run(request, **kwargs) # pylint:disable=protected-access
pipeline_response = self._client._client._pipeline.run(request, **kwargs) # pylint: disable=protected-access
response = pipeline_response.http_response

if response.status_code == 403:
Expand Down Expand Up @@ -328,10 +331,10 @@ def _batch_send( # pylint: disable=inconsistent-return-statements
)
return transaction_result

def _parameter_filter_substitution( # pylint: disable = R0201
def _parameter_filter_substitution( # pylint: disable=no-self-use
self,
parameters, # type: dict[str,str]
filter # type: str # pylint: disable = W0622
filter # type: str pylint: disable=redefined-builtin
):
"""Replace user defined parameter in filter
:param parameters: User defined parameters
Expand All @@ -354,7 +357,7 @@ def _parameter_filter_substitution( # pylint: disable = R0201
filter_strings[index] = "'{}'".format(val)
return ' '.join(filter_strings)

return filter # pylint: disable = W0622
return filter


class TransportWrapper(HttpTransport):
Expand All @@ -378,7 +381,7 @@ def close(self):
def __enter__(self):
pass

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


Expand Down
36 changes: 19 additions & 17 deletions sdk/tables/azure-data-tables/azure/data/tables/_deserialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
# pylint: disable=unused-argument
from typing import ( # pylint: disable=unused-import
Union,
Optional,
Any,
Iterable,
Dict,
List,
Type,
Tuple,
TYPE_CHECKING,
)

from typing import TYPE_CHECKING
from uuid import UUID
import logging
import datetime
Expand All @@ -37,6 +27,18 @@
except ImportError:
from urllib2 import quote # type: ignore

if TYPE_CHECKING:
from typing import ( # pylint: disable=ungrouped-imports
Union,
Optional,
Any,
Iterable,
Dict,
List,
Type,
Tuple,
)


def url_quote(url):
return quote(url)
Expand Down Expand Up @@ -81,7 +83,7 @@ def _from_entity_int64(value):
zero = datetime.timedelta(0) # same as 00:00


class Timezone(datetime.tzinfo): # pylint: disable : W0223
class Timezone(datetime.tzinfo):
def utcoffset(self, dt):
return zero

Expand Down Expand Up @@ -183,18 +185,18 @@ def _convert_to_entity(entry_element):
mtype = edmtypes.get(name)

# Add type for Int32
if type(value) is int and mtype is None: # pylint:disable=C0123
if isinstance(value, int) and mtype is None:
mtype = EdmType.INT32

if value >= 2 ** 31 or value < (-(2 ** 31)):
mtype = EdmType.INT64

# Add type for String
try:
if type(value) is unicode and mtype is None: # pylint:disable=C0123
if isinstance(value, unicode) and mtype is None:
mtype = EdmType.STRING
except NameError:
if type(value) is str and mtype is None: # pylint:disable=C0123
if isinstance(value, str) and mtype is None:
mtype = EdmType.STRING

# no type info, property should parse automatically
Expand All @@ -216,7 +218,7 @@ def _convert_to_entity(entry_element):
etag = "W/\"datetime'" + url_quote(timestamp) + "'\""
entity["etag"] = etag

entity._set_metadata() # pylint: disable = W0212
entity._set_metadata() # pylint: disable=protected-access
return entity


Expand Down
8 changes: 4 additions & 4 deletions sdk/tables/azure-data-tables/azure/data/tables/_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ class TableEntity(dict):

def _set_metadata(self):
if "Timestamp" in self.keys():
self._metadata = { # pylint:disable=W0201
self._metadata = { # pylint: disable=attribute-defined-outside-init
"etag": self.pop("etag"),
"timestamp": self.pop("Timestamp"),
}
else:
self._metadata = {"etag": self.pop("etag")} # pylint:disable=W0201
self._metadata = {"etag": self.pop("etag")} # pylint: disable=attribute-defined-outside-init

def metadata(self, **kwargs): # pylint: disable = W0613
def metadata(self):
# type: (...) -> Dict[str,Any]
"""Resets metadata to be a part of the entity
:return Dict of entity metadata
Expand Down Expand Up @@ -83,7 +83,7 @@ class EntityProperty(object):
def __init__(
self,
value=None, # type: Any
type=None, # type: Union[str,EdmType] # pylint:disable=W0622
type=None, # type: Union[str,EdmType] pylint: disable=redefined-builtin
):
"""
Represents an Azure Table. Returned by list_tables.
Expand Down
16 changes: 8 additions & 8 deletions sdk/tables/azure-data-tables/azure/data/tables/_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ def _validate_not_none(param_name, param):

def _wrap_exception(ex, desired_type):
msg = ""
if len(ex.args) > 0: # pylint: disable=C1801
if len(ex.args) > 0:
msg = ex.args[0]
if version_info >= (3,): # pylint: disable=R1705
if version_info >= (3,):
# Automatic chaining in Python 3 means we keep the trace
return desired_type(msg)
else:
# There isn't a good solution in 2 for keeping the stack trace
# in general, or that will not result in an error in 3
# However, we can keep the previous error type and message
# TODO: In the future we will log the trace
return desired_type("{}: {}".format(ex.__class__.__name__, msg))

# There isn't a good solution in 2 for keeping the stack trace
# in general, or that will not result in an error in 3
# However, we can keep the previous error type and message
# TODO: In the future we will log the trace
return desired_type("{}: {}".format(ex.__class__.__name__, msg))


def _validate_table_name(table_name):
Expand Down
30 changes: 16 additions & 14 deletions sdk/tables/azure-data-tables/azure/data/tables/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class TableServiceStats(GenTableServiceStats):
:type geo_replication: ~azure.data.tables.models.GeoReplication
"""

def __init__(self, geo_replication=None, **kwargs): # pylint:disable=W0231
def __init__( # pylint: disable=super-init-not-called
self, geo_replication=None, **kwargs
):
self.geo_replication = geo_replication


Expand Down Expand Up @@ -77,9 +79,9 @@ class AccessPolicy(GenAccessPolicy):
:type start: ~datetime.datetime or str
"""

def __init__(
def __init__( # pylint: disable=super-init-not-called
self, permission=None, expiry=None, start=None, **kwargs
): # pylint:disable=W0231
):
self.start = start
self.expiry = expiry
self.permission = permission
Expand All @@ -98,7 +100,7 @@ class TableAnalyticsLogging(GeneratedLogging):
The retention policy for the metrics.
"""

def __init__( # pylint:disable=W0231
def __init__( # pylint: disable=super-init-not-called
self, **kwargs # type: Any
):
# type: (...)-> None
Expand All @@ -118,7 +120,7 @@ def _from_generated(cls, generated):
delete=generated.delete,
read=generated.read,
write=generated.write,
retention_policy=RetentionPolicy._from_generated( # pylint:disable=protected-access
retention_policy=RetentionPolicy._from_generated( # pylint: disable=protected-access
generated.retention_policy
)
)
Expand All @@ -137,7 +139,7 @@ class Metrics(GeneratedMetrics):
The retention policy for the metrics.
"""

def __init__( # pylint:disable=super-init-not-called
def __init__( # pylint: disable=super-init-not-called
self,
**kwargs # type: Any
):
Expand Down Expand Up @@ -166,7 +168,7 @@ def _from_generated(cls, generated):


class RetentionPolicy(GeneratedRetentionPolicy):
def __init__( # pylint:disable=W0231
def __init__( # pylint: disable=super-init-not-called
self,
enabled=False, # type: bool
days=None, # type: int
Expand All @@ -191,7 +193,7 @@ def __init__( # pylint:disable=W0231
raise ValueError("If policy is enabled, 'days' must be specified.")

@classmethod
def _from_generated(cls, generated, **kwargs): # pylint:disable=W0613
def _from_generated(cls, generated, **kwargs): # pylint: disable=unused-argument
# type: (...) -> cls
"""The retention policy which determines how long the associated data should
persist.
Expand Down Expand Up @@ -239,7 +241,7 @@ class CorsRule(GeneratedCorsRule):
headers. Each header can be up to 256 characters.
"""

def __init__( # pylint:disable=W0231
def __init__( # pylint: disable=super-init-not-called
self,
allowed_origins, # type: list[str]
allowed_methods, # type: list[str]
Expand Down Expand Up @@ -307,7 +309,7 @@ def _get_next_cb(self, continuation_token, **kwargs):
def _extract_data_cb(self, get_next_return):
self.location_mode, self._response, self._headers = get_next_return
props_list = [
TableItem._from_generated(t, **self._headers) for t in self._response.value # pylint:disable=protected-access
TableItem._from_generated(t, **self._headers) for t in self._response.value # pylint: disable=protected-access
]
return self._headers[NEXT_TABLE_NAME] or None, props_list

Expand Down Expand Up @@ -416,7 +418,7 @@ def from_string(
cls,
permission, # type: str
**kwargs
): # pylint:disable=W0613
):
"""Create AccountSasPermissions from a string.

To specify read, write, delete, etc. permissions you need only to
Expand Down Expand Up @@ -490,7 +492,7 @@ def __init__(self, table_name, **kwargs):
self.date = kwargs.get("date") or kwargs.get("Date")

@classmethod
def _from_generated(cls, generated, **kwargs): # pylint:disable=W0613
def _from_generated(cls, generated, **kwargs):
# type: (obj, **Any) -> cls
return cls(generated.table_name, **kwargs)

Expand Down Expand Up @@ -670,7 +672,7 @@ class AccountSasPermissions(object):
Valid for the following Object resource type only: queue messages.
"""

def __init__(self, **kwargs): # pylint: disable=redefined-builtin
def __init__(self, **kwargs):
self.read = kwargs.pop("read", None)
self.write = kwargs.pop("write", None)
self.delete = kwargs.pop("delete", None)
Expand All @@ -694,7 +696,7 @@ def __str__(self):
return self._str

@classmethod
def from_string(cls, permission, **kwargs): # pylint:disable=W0613
def from_string(cls, permission, **kwargs):
"""Create AccountSasPermissions from a string.

To specify read, write, delete, etc. permissions you need only to
Expand Down
8 changes: 4 additions & 4 deletions sdk/tables/azure-data-tables/azure/data/tables/_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def on_response(self, request, response):


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 @@ -293,7 +293,7 @@ def on_request(self, request):


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 @@ -485,7 +485,7 @@ def _set_next_host_location(self, settings, request): # pylint: disable=no-self
def configure_retries(
self, request
): # pylint: disable=no-self-use, arguments-differ
# type: (...)-> dict
# type: (...) -> Dict[Any, Any]
"""
:param Any request:
:param kwargs:
Expand Down Expand Up @@ -532,7 +532,7 @@ def sleep(self, settings, transport): # pylint: disable=arguments-differ

def increment(
self, settings, request, response=None, error=None, **kwargs
): # pylint:disable=unused-argument, arguments-differ
): # pylint: disable=unused-argument, arguments-differ
# type: (...)->None
"""Increment the retry counters.

Expand Down
Loading