From e5f91ce479ff8f1f3c6c64d418708e137e68a70a Mon Sep 17 00:00:00 2001 From: Raildo Mascena Date: Wed, 17 Feb 2016 13:24:08 -0300 Subject: [PATCH] Avoid using `len(x)` to check if x is empty This cases are using `len()` to check if collection has items. As collections have a boolean representation too, directly check for true / false. Change-Id: I1e552db99fbe6d33ad43bb710af924261dcebb46 --- keystone/common/validation/validators.py | 2 +- keystone/oauth1/controllers.py | 2 +- keystone/tests/hacking/checks.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/keystone/common/validation/validators.py b/keystone/common/validation/validators.py index a457417662..7cc3f78923 100644 --- a/keystone/common/validation/validators.py +++ b/keystone/common/validation/validators.py @@ -43,7 +43,7 @@ class SchemaValidator(object): except jsonschema.ValidationError as ex: # NOTE: For whole OpenStack message consistency, this error # message has been written in a format consistent with WSME. - if len(ex.path) > 0: + if ex.path: # NOTE(lbragstad): Here we could think about using iter_errors # as a method of providing invalid parameters back to the # user. diff --git a/keystone/oauth1/controllers.py b/keystone/oauth1/controllers.py index db793ced3e..5003a75449 100644 --- a/keystone/oauth1/controllers.py +++ b/keystone/oauth1/controllers.py @@ -303,7 +303,7 @@ class OAuthControllerV3(controller.V3Controller): body=context['query_string'], headers=headers) params = oauth1.extract_non_oauth_params(b) - if len(params) != 0: + if params: msg = _('There should not be any non-oauth parameters') raise exception.Unauthorized(message=msg) diff --git a/keystone/tests/hacking/checks.py b/keystone/tests/hacking/checks.py index 29188fa6d5..dd8a44e3db 100644 --- a/keystone/tests/hacking/checks.py +++ b/keystone/tests/hacking/checks.py @@ -305,7 +305,7 @@ class CheckForLoggingIssues(BaseASTChecker): return super(CheckForLoggingIssues, self).generic_visit(node) # the call must have arguments - if not len(node.args): + if not node.args: return super(CheckForLoggingIssues, self).generic_visit(node) if method_name == 'debug':