Fix remaining flake8 issues

Disabling W504 and W605 for now as there are too many instances.
This commit is contained in:
Chih-Hsuan Yen 2019-10-27 21:00:01 +08:00
parent 18173a5951
commit 84fb52d0a2
No known key found for this signature in database
GPG Key ID: 0453A6CA23C56315
10 changed files with 28 additions and 35 deletions

View File

@ -1,5 +1,5 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import logging # import logging
# logging.getLogger('boto').setLevel(logging.CRITICAL) # logging.getLogger('boto').setLevel(logging.CRITICAL)
__title__ = 'moto' __title__ = 'moto'

View File

@ -96,11 +96,11 @@ class CloudWatchResponse(BaseResponse):
extended_statistics = self._get_param('ExtendedStatistics') extended_statistics = self._get_param('ExtendedStatistics')
dimensions = self._get_param('Dimensions') dimensions = self._get_param('Dimensions')
if unit or extended_statistics or dimensions: if unit or extended_statistics or dimensions:
raise NotImplemented() raise NotImplementedError()
# TODO: this should instead throw InvalidParameterCombination # TODO: this should instead throw InvalidParameterCombination
if not statistics: if not statistics:
raise NotImplemented("Must specify either Statistics or ExtendedStatistics") raise NotImplementedError("Must specify either Statistics or ExtendedStatistics")
datapoints = self.cloudwatch_backend.get_metric_statistics(namespace, metric_name, start_time, end_time, period, statistics) datapoints = self.cloudwatch_backend.get_metric_statistics(namespace, metric_name, start_time, end_time, period, statistics)
template = self.response_template(GET_METRIC_STATISTICS_TEMPLATE) template = self.response_template(GET_METRIC_STATISTICS_TEMPLATE)

View File

@ -1,7 +1,5 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import re import re
import six
import re
from collections import deque from collections import deque
from collections import namedtuple from collections import namedtuple
@ -48,11 +46,11 @@ def get_expected(expected):
path = AttributePath([key]) path = AttributePath([key])
if 'Exists' in cond: if 'Exists' in cond:
if cond['Exists']: if cond['Exists']:
conditions.append(FuncAttrExists(path)) conditions.append(FuncAttrExists(path))
else: else:
conditions.append(FuncAttrNotExists(path)) conditions.append(FuncAttrNotExists(path))
elif 'Value' in cond: elif 'Value' in cond:
conditions.append(OpEqual(path, AttributeValue(cond['Value']))) conditions.append(OpEqual(path, AttributeValue(cond['Value'])))
elif 'ComparisonOperator' in cond: elif 'ComparisonOperator' in cond:
operator_name = cond['ComparisonOperator'] operator_name = cond['ComparisonOperator']
values = [ values = [
@ -221,7 +219,6 @@ class ConditionExpressionParser:
# -------------- # --------------
LITERAL = 'LITERAL' LITERAL = 'LITERAL'
class Nonterminal: class Nonterminal:
"""Enum defining nonterminals for productions.""" """Enum defining nonterminals for productions."""
@ -240,7 +237,6 @@ class ConditionExpressionParser:
RIGHT_PAREN = 'RIGHT_PAREN' RIGHT_PAREN = 'RIGHT_PAREN'
WHITESPACE = 'WHITESPACE' WHITESPACE = 'WHITESPACE'
Node = namedtuple('Node', ['nonterminal', 'kind', 'text', 'value', 'children']) Node = namedtuple('Node', ['nonterminal', 'kind', 'text', 'value', 'children'])
def _lex_condition_expression(self): def _lex_condition_expression(self):
@ -286,11 +282,10 @@ class ConditionExpressionParser:
if match: if match:
match_text = match.group() match_text = match.group()
break break
else: # pragma: no cover else: # pragma: no cover
raise ValueError("Cannot parse condition starting at: " + raise ValueError("Cannot parse condition starting at: " +
remaining_expression) remaining_expression)
value = match_text
node = self.Node( node = self.Node(
nonterminal=nonterminal, nonterminal=nonterminal,
kind=self.Kind.LITERAL, kind=self.Kind.LITERAL,
@ -351,7 +346,6 @@ class ConditionExpressionParser:
'size', 'size',
} }
if name.lower() in reserved: if name.lower() in reserved:
# e.g. AND # e.g. AND
nonterminal = reserved[name.lower()] nonterminal = reserved[name.lower()]
@ -748,14 +742,13 @@ class ConditionExpressionParser:
elif node.kind == self.Kind.FUNCTION: elif node.kind == self.Kind.FUNCTION:
# size() # size()
function_node = node.children[0] function_node = node.children[0]
arguments = node.children[1:] arguments = node.children[1:]
function_name = function_node.value function_name = function_node.value
arguments = [self._make_operand(arg) for arg in arguments] arguments = [self._make_operand(arg) for arg in arguments]
return FUNC_CLASS[function_name](*arguments) return FUNC_CLASS[function_name](*arguments)
else: # pragma: no cover else: # pragma: no cover
raise ValueError("Unknown operand: %r" % node) raise ValueError("Unknown operand: %r" % node)
def _make_op_condition(self, node): def _make_op_condition(self, node):
if node.kind == self.Kind.OR: if node.kind == self.Kind.OR:
lhs, rhs = node.children lhs, rhs = node.children
@ -796,7 +789,7 @@ class ConditionExpressionParser:
return COMPARATOR_CLASS[comparator.value]( return COMPARATOR_CLASS[comparator.value](
self._make_operand(lhs), self._make_operand(lhs),
self._make_operand(rhs)) self._make_operand(rhs))
else: # pragma: no cover else: # pragma: no cover
raise ValueError("Unknown expression node kind %r" % node.kind) raise ValueError("Unknown expression node kind %r" % node.kind)
def _assert(self, condition, message, nodes): def _assert(self, condition, message, nodes):

View File

@ -1229,7 +1229,7 @@ class AmiBackend(object):
images = [ami for ami in images if ami.id in ami_ids] images = [ami for ami in images if ami.id in ami_ids]
if len(images) == 0: if len(images) == 0:
raise InvalidAMIIdError(ami_ids) raise InvalidAMIIdError(ami_ids)
else: else:
# Limit images by launch permissions # Limit images by launch permissions
if exec_users: if exec_users:
@ -3720,8 +3720,8 @@ class VPNConnection(TaggedEC2Resource):
self.static_routes = None self.static_routes = None
def get_filter_value(self, filter_name): def get_filter_value(self, filter_name):
return super(VPNConnection, self).get_filter_value( return super(VPNConnection, self).get_filter_value(
filter_name, 'DescribeVpnConnections') filter_name, 'DescribeVpnConnections')
class VPNConnectionBackend(object): class VPNConnectionBackend(object):
@ -3950,8 +3950,8 @@ class VpnGateway(TaggedEC2Resource):
super(VpnGateway, self).__init__() super(VpnGateway, self).__init__()
def get_filter_value(self, filter_name): def get_filter_value(self, filter_name):
return super(VpnGateway, self).get_filter_value( return super(VpnGateway, self).get_filter_value(
filter_name, 'DescribeVpnGateways') filter_name, 'DescribeVpnGateways')
class VpnGatewayAttachment(object): class VpnGatewayAttachment(object):
@ -4015,8 +4015,8 @@ class CustomerGateway(TaggedEC2Resource):
super(CustomerGateway, self).__init__() super(CustomerGateway, self).__init__()
def get_filter_value(self, filter_name): def get_filter_value(self, filter_name):
return super(CustomerGateway, self).get_filter_value( return super(CustomerGateway, self).get_filter_value(
filter_name, 'DescribeCustomerGateways') filter_name, 'DescribeCustomerGateways')
class CustomerGatewayBackend(object): class CustomerGatewayBackend(object):

View File

@ -158,8 +158,8 @@ class TaskDefinition(BaseObject):
if (original_resource.family != family or if (original_resource.family != family or
original_resource.container_definitions != container_definitions or original_resource.container_definitions != container_definitions or
original_resource.volumes != volumes): original_resource.volumes != volumes):
# currently TaskRoleArn isn't stored at TaskDefinition # currently TaskRoleArn isn't stored at TaskDefinition
# instances # instances
ecs_backend = ecs_backends[region_name] ecs_backend = ecs_backends[region_name]
ecs_backend.deregister_task_definition(original_resource.arn) ecs_backend.deregister_task_definition(original_resource.arn)
return ecs_backend.register_task_definition( return ecs_backend.register_task_definition(

View File

@ -163,7 +163,7 @@ class IoTDataPlaneBackend(BaseBackend):
raise InvalidRequestException('State contains an invalid node') raise InvalidRequestException('State contains an invalid node')
if 'version' in payload and thing.thing_shadow.version != payload['version']: if 'version' in payload and thing.thing_shadow.version != payload['version']:
raise ConflictException('Version conflict') raise ConflictException('Version conflict')
new_shadow = FakeShadow.create_from_previous_version(thing.thing_shadow, payload) new_shadow = FakeShadow.create_from_previous_version(thing.thing_shadow, payload)
thing.thing_shadow = new_shadow thing.thing_shadow = new_shadow
return thing.thing_shadow return thing.thing_shadow

View File

@ -875,8 +875,8 @@ class RDS2Backend(BaseBackend):
database = self.describe_databases(db_instance_identifier)[0] database = self.describe_databases(db_instance_identifier)[0]
# todo: certain rds types not allowed to be stopped at this time. # todo: certain rds types not allowed to be stopped at this time.
if database.is_replica or database.multi_az: if database.is_replica or database.multi_az:
# todo: more db types not supported by stop/start instance api # todo: more db types not supported by stop/start instance api
raise InvalidDBClusterStateFaultError(db_instance_identifier) raise InvalidDBClusterStateFaultError(db_instance_identifier)
if database.status != 'available': if database.status != 'available':
raise InvalidDBInstanceStateError(db_instance_identifier, 'stop') raise InvalidDBInstanceStateError(db_instance_identifier, 'stop')
if db_snapshot_identifier: if db_snapshot_identifier:

View File

@ -244,7 +244,7 @@ class ResourceGroupsTaggingAPIBackend(BaseBackend):
def get_kms_tags(kms_key_id): def get_kms_tags(kms_key_id):
result = [] result = []
for tag in self.kms_backend.list_resource_tags(kms_key_id): for tag in self.kms_backend.list_resource_tags(kms_key_id):
result.append({'Key': tag['TagKey'], 'Value': tag['TagValue']}) result.append({'Key': tag['TagKey'], 'Value': tag['TagValue']})
return result return result
if not resource_type_filters or 'kms' in resource_type_filters: if not resource_type_filters or 'kms' in resource_type_filters:

View File

@ -210,9 +210,9 @@ class Command(BaseModel):
'An error occurred (InvocationDoesNotExist) when calling the GetCommandInvocation operation') 'An error occurred (InvocationDoesNotExist) when calling the GetCommandInvocation operation')
if plugin_name is not None and invocation['PluginName'] != plugin_name: if plugin_name is not None and invocation['PluginName'] != plugin_name:
raise RESTError( raise RESTError(
'InvocationDoesNotExist', 'InvocationDoesNotExist',
'An error occurred (InvocationDoesNotExist) when calling the GetCommandInvocation operation') 'An error occurred (InvocationDoesNotExist) when calling the GetCommandInvocation operation')
return invocation return invocation

View File

@ -15,5 +15,5 @@ commands =
nosetests {posargs} nosetests {posargs}
[flake8] [flake8]
ignore = E128,E501 ignore = E128,E501,W504,W605
exclude = moto/packages,dist exclude = moto/packages,dist