Fix and enable flake8 F812

F812 list comprehension redefines

List comprehension don't have scope so redefining variables can lead to
unexpected behaviors

Change-Id: I85484dfcd4fa391195ea7be75aadc7897da4739c
This commit is contained in:
Joe Gordon 2013-05-28 06:52:55 +03:00
parent a3e6133628
commit d9c145c7b8
3 changed files with 11 additions and 11 deletions

View File

@ -2854,18 +2854,18 @@ def quota_reserve(context, resources, quotas, deltas, expire,
# a best-effort mechanism.
# Check for deltas that would go negative
unders = [resource for resource, delta in deltas.items()
unders = [res for res, delta in deltas.items()
if delta < 0 and
delta + usages[resource].in_use < 0]
delta + usages[res].in_use < 0]
# Now, let's check the quotas
# NOTE(Vek): We're only concerned about positive increments.
# If a project has gone over quota, we want them to
# be able to reduce their usage without any
# problems.
overs = [resource for resource, delta in deltas.items()
if quotas[resource] >= 0 and delta >= 0 and
quotas[resource] < delta + usages[resource].total]
overs = [res for res, delta in deltas.items()
if quotas[res] >= 0 and delta >= 0 and
quotas[res] < delta + usages[res].total]
# NOTE(Vek): The quota check needs to be in the transaction,
# but the transaction doesn't fail just because
@ -2877,12 +2877,12 @@ def quota_reserve(context, resources, quotas, deltas, expire,
# Create the reservations
if not overs:
reservations = []
for resource, delta in deltas.items():
for res, delta in deltas.items():
reservation = reservation_create(elevated,
str(uuid.uuid4()),
usages[resource],
usages[res],
project_id,
resource, delta, expire,
res, delta, expire,
session=session)
reservations.append(reservation.uuid)
@ -2899,7 +2899,7 @@ def quota_reserve(context, resources, quotas, deltas, expire,
# To prevent this, we only update the
# reserved value if the delta is positive.
if delta > 0:
usages[resource].reserved += delta
usages[res].reserved += delta
# Apply updates to the usages table
for usage_ref in usages.values():

View File

@ -126,7 +126,7 @@ class ServersTest(integrated_helpers._IntegratedTestBase):
# It should also be in the all-servers list
servers = self.api.get_servers()
server_ids = [server['id'] for server in servers]
server_ids = [s['id'] for s in servers]
self.assertTrue(created_server_id in server_ids)
found_server = self._wait_for_state_change(found_server, 'BUILD')

View File

@ -40,7 +40,7 @@ commands =
commands = {posargs}
[flake8]
ignore = E12,E711,E712,H302,H303,H403,H404,F403,F811,F812,F823,F841
ignore = E12,E711,E712,H302,H303,H403,H404,F403,F811,F823,F841
builtins = _
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,plugins,tools