From fb4f131d845a8626c932d0bdfabeb0880ad1c903 Mon Sep 17 00:00:00 2001 From: Pavlo Shchelokovskyy Date: Sun, 14 Dec 2014 20:38:44 +0200 Subject: [PATCH] Enable F402 and F812 style checks Checks for shadowing by loop variables Change-Id: I6fd89d34fee35d08b5b15f2ee0015f1ed685f0be --- heat/engine/resources/instance.py | 4 ++-- heat/engine/resources/internet_gateway.py | 12 ++++++------ heat/engine/resources/random_string.py | 4 ++-- heat/engine/resources/user.py | 6 +++--- heat/engine/stack.py | 4 ++-- heat/tests/test_waitcondition.py | 2 +- tox.ini | 4 +--- 7 files changed, 17 insertions(+), 19 deletions(-) diff --git a/heat/engine/resources/instance.py b/heat/engine/resources/instance.py index e4b02cc048..eeeed7953e 100644 --- a/heat/engine/resources/instance.py +++ b/heat/engine/resources/instance.py @@ -504,8 +504,8 @@ class Instance(resource.Resource): unsorted_nics.append(nic) sorted_nics = sorted(unsorted_nics, key=lambda nic: int(nic['DeviceIndex'])) - nics = [{'port-id': nic['NetworkInterfaceId']} - for nic in sorted_nics] + nics = [{'port-id': snic['NetworkInterfaceId']} + for snic in sorted_nics] else: # if SubnetId property in Instance, ensure subnet exists if subnet_id: diff --git a/heat/engine/resources/internet_gateway.py b/heat/engine/resources/internet_gateway.py index efce1bf692..3e80b581db 100644 --- a/heat/engine/resources/internet_gateway.py +++ b/heat/engine/resources/internet_gateway.py @@ -100,11 +100,11 @@ class VPCGatewayAttachment(resource.Resource): default_client_name = 'neutron' def _vpc_route_tables(self): - for resource in self.stack.itervalues(): - if (resource.has_interface('AWS::EC2::RouteTable') and - resource.properties.get(route_table.RouteTable.VPC_ID) == + for res in self.stack.itervalues(): + if (res.has_interface('AWS::EC2::RouteTable') and + res.properties.get(route_table.RouteTable.VPC_ID) == self.properties.get(self.VPC_ID)): - yield resource + yield res def add_dependencies(self, deps): super(VPCGatewayAttachment, self).add_dependencies(deps) @@ -112,8 +112,8 @@ class VPCGatewayAttachment(resource.Resource): # VpcId as this VpcId. # All route tables must exist before gateway attachment # as attachment happens to routers (not VPCs) - for route_table in self._vpc_route_tables(): - deps += (self, route_table) + for route_tbl in self._vpc_route_tables(): + deps += (self, route_tbl) def handle_create(self): client = self.neutron() diff --git a/heat/engine/resources/random_string.py b/heat/engine/resources/random_string.py index 17d74d54ed..f964e5c1e3 100644 --- a/heat/engine/resources/random_string.py +++ b/heat/engine/resources/random_string.py @@ -180,7 +180,7 @@ class RandomString(resource.Resource): for char_seq in char_sequences: seq = char_seq[self.CHARACTER_SEQUENCES_SEQUENCE] seq_min = char_seq[self.CHARACTER_SEQUENCES_MIN] - for _ in xrange(seq_min): + for i in xrange(seq_min): random_string += random.choice(seq) if char_classes: @@ -188,7 +188,7 @@ class RandomString(resource.Resource): cclass_class = char_class[self.CHARACTER_CLASSES_CLASS] cclass_seq = self._sequences[cclass_class] cclass_min = char_class[self.CHARACTER_CLASSES_MIN] - for _ in xrange(cclass_min): + for i in xrange(cclass_min): random_string += random.choice(cclass_seq) def random_class_char(): diff --git a/heat/engine/resources/user.py b/heat/engine/resources/user.py index de3d442c84..2b491aab8c 100644 --- a/heat/engine/resources/user.py +++ b/heat/engine/resources/user.py @@ -292,9 +292,9 @@ class AccessPolicy(resource.Resource): resources = self.properties[self.ALLOWED_RESOURCES] # All of the provided resource names must exist in this stack - for resource in resources: - if resource not in self.stack: - msg = _("AccessPolicy resource %s not in stack") % resource + for res in resources: + if res not in self.stack: + msg = _("AccessPolicy resource %s not in stack") % res raise exception.StackValidationFailed(message=msg) def access_allowed(self, resource_name): diff --git a/heat/engine/stack.py b/heat/engine/stack.py index 9f3f203fa9..b2375d63df 100644 --- a/heat/engine/stack.py +++ b/heat/engine/stack.py @@ -244,8 +244,8 @@ class Stack(collections.Mapping): def _get_dependencies(resources): '''Return the dependency graph for a list of resources.''' deps = dependencies.Dependencies() - for resource in resources: - resource.add_dependencies(deps) + for res in resources: + res.add_dependencies(deps) return deps diff --git a/heat/tests/test_waitcondition.py b/heat/tests/test_waitcondition.py index 844a8cc965..c0da4fe9d7 100644 --- a/heat/tests/test_waitcondition.py +++ b/heat/tests/test_waitcondition.py @@ -704,7 +704,7 @@ class WaitConditionUpdateTest(common.HeatTestCase): self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state) def _handle_signal(self, rsrc, metadata, times=1): - for time in range(times): + for t in range(times): metadata['UniqueId'] = metadata['UniqueId'] * 2 ret = rsrc.handle_signal(metadata) self.assertEqual("status:%s reason:%s" % diff --git a/tox.ini b/tox.ini index 54df710b75..6adc50bbdd 100644 --- a/tox.ini +++ b/tox.ini @@ -54,8 +54,6 @@ commands = [flake8] # E251 unexpected spaces around keyword / parameter equals -# F402 import shadowed by loop variable -# F812 list comprehension redefines variable # H202 assertRaises Exception too broad # H233 Python 3.x incompatible use of print operator # H305 imports not grouped correctly @@ -65,7 +63,7 @@ commands = # H405 multi line docstring summary not separated with an empty line # H803 no full stop at the end of the commit message # H904 Wrap long lines in parentheses instead of a backslash -ignore = E251,F402,F812,H202,H233,H305,H307,H402,H404,H405,H803,H904 +ignore = E251,H202,H233,H305,H307,H402,H404,H405,H803,H904 show-source = true exclude=.venv,.git,.tox,dist,*openstack/common*,*lib/python*,*egg,tools,build max-complexity=20