Fix use the fact that empty sequences are false.

For sequences(strings, lists, tuples), in order to consistent with
pep8 recommendations, 'if len(seq)' should be replaced with 'if seq',
and 'if not len(seq)' should be replaced with 'if not seq'.

Change-Id: Ieb2c90b7f87b54361a2c291a838550227fde9fbe
Closes-Bug: #1156472
This commit is contained in:
wanghong 2013-12-24 16:04:13 +08:00
parent a22520be14
commit 3c66870de2
9 changed files with 9 additions and 9 deletions

View File

@ -141,7 +141,7 @@ class Assignment(kvs.Base, assignment.Driver):
'Cannot remove role that has not been granted, %s') %
role_id)
if len(metadata_ref['roles']):
if metadata_ref['roles']:
self._update_metadata(user_id, tenant_id, metadata_ref)
else:

View File

@ -341,7 +341,7 @@ class Assignment(sql.Base, assignment.Driver):
'Cannot remove role that has not been granted, %s') %
role_id)
if len(metadata_ref['roles']):
if metadata_ref['roles']:
self._update_metadata(session, user_id, tenant_id,
metadata_ref)
else:

View File

@ -399,7 +399,7 @@ class Auth(controller.V3Controller):
auth_response['methods'].append(method_name)
auth_response[method_name] = resp
if len(auth_response["methods"]) > 0:
if auth_response["methods"]:
# authentication continuation required
raise exception.AdditionalAuthRequired(auth_response)

View File

@ -71,7 +71,7 @@ class OAuth(auth.AuthMethodHandler):
consumer_obj,
token=acc_token_obj)
if len(params) != 0:
if params:
msg = _('There should not be any non-oauth parameters')
raise exception.Unauthorized(message=msg)

View File

@ -195,7 +195,7 @@ def filterprotected(*filters):
#
# First any query filter parameters
target = dict()
if len(filters) > 0:
if filters:
for item in filters:
if item in context['query_string']:
target[item] = context['query_string'][item]

View File

@ -125,7 +125,7 @@ class XmlDeserializer(object):
values = values or text or {}
decoded_tag = XmlDeserializer._qualified_name(element.tag, namespace)
list_item_tag = None
if (decoded_tag[-1] == 's' and len(values) == 0 and
if (decoded_tag[-1] == 's' and not values and
decoded_tag != 'access'):
# FIXME(gyee): special-case lists for now unti we
# figure out how to properly handle them.

View File

@ -33,7 +33,7 @@ class EndpointFilterCatalog(sql.Catalog):
refs = self.endpoint_filter_api.list_endpoints_for_project(project_id)
if (len(refs) == 0 and
if (not refs and
CONF.endpoint_filter.return_all_endpoints_if_no_filter):
return super(EndpointFilterCatalog, self).get_v3_catalog(
user_id, project_id, metadata=metadata)

View File

@ -265,7 +265,7 @@ class OAuthControllerV3(controller.V3Controller):
consumer_obj,
token=req_token_obj)
if len(params) != 0:
if params:
msg = _('There should not be any non-oauth parameters')
raise exception.Unauthorized(message=msg)

View File

@ -280,7 +280,7 @@ class FakeLdap(object):
values[:] = _process_attr(k, v)
elif cmd == ldap.MOD_DELETE:
if v is None:
if len(values) == 0:
if not values:
LOG.debug(_('FakeLdap modify item failed: '
'item has no attribute "%s" to delete'), k)
raise ldap.NO_SUCH_ATTRIBUTE