From cf088fbb72094b8b8e22b3dfbd54b162fef4906d Mon Sep 17 00:00:00 2001 From: lzyeval Date: Wed, 4 Jan 2012 08:49:49 +0800 Subject: [PATCH] PEP8 cleanup Fixes bug #911531 The None, True, and False values are singletons. All variable *comparisons* to singletons should use 'is' or 'is not'. All variable *evaluations* to boolean should use 'if' or 'if not'. All Object type comparisons should use isinstance() instead of comparing types directly Change-Id: Ie1b3e18bad22a2baeb79d50928267a4cac0a55e4 --- horizon/horizon/api/swift.py | 4 +--- horizon/horizon/base.py | 4 ++-- horizon/horizon/dashboards/syspanel/instances/views.py | 2 +- horizon/horizon/templatetags/horizon.py | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/horizon/horizon/api/swift.py b/horizon/horizon/api/swift.py index 455cb806f..a4589418f 100644 --- a/horizon/horizon/api/swift.py +++ b/horizon/horizon/api/swift.py @@ -117,9 +117,7 @@ def swift_copy_object(request, orig_container_name, orig_object_name, container = swift_api(request).get_container(orig_container_name) - if swift_object_exists(request, - new_container_name, - new_object_name) == True: + if swift_object_exists(request, new_container_name, new_object_name): raise Exception('Object with name %s already exists in container %s' % (new_object_name, new_container_name)) diff --git a/horizon/horizon/base.py b/horizon/horizon/base.py index a7a1d6439..22acf5a36 100644 --- a/horizon/horizon/base.py +++ b/horizon/horizon/base.py @@ -344,7 +344,7 @@ class Dashboard(Registry, HorizonComponent): dashboard in order. """ registered = copy.copy(self._registry) - if type(self.panels) is dict: + if isinstance(self.panels, dict): panels = {} for heading, items in self.panels.iteritems(): panels.setdefault(heading, []) @@ -412,7 +412,7 @@ class Dashboard(Registry, HorizonComponent): package = '.'.join(self.__module__.split('.')[:-1]) mod = import_module(package) panels = [] - if type(self.panels) is dict: + if isinstance(self.panels, dict): [panels.extend(values) for values in self.panels.values()] else: panels = self.panels diff --git a/horizon/horizon/dashboards/syspanel/instances/views.py b/horizon/horizon/dashboards/syspanel/instances/views.py index 056d0feec..c78057e44 100644 --- a/horizon/horizon/dashboards/syspanel/instances/views.py +++ b/horizon/horizon/dashboards/syspanel/instances/views.py @@ -99,7 +99,7 @@ class GlobalSummary(object): # usage = usage._info for k in usage._attrs: v = usage.__getattr__(k) - if type(v) in [float, int]: + if isinstance(v, (float, int)): if not k in self.summary: self.summary[k] = 0 self.summary[k] += v diff --git a/horizon/horizon/templatetags/horizon.py b/horizon/horizon/templatetags/horizon.py index be6210e0c..f83dfeb91 100644 --- a/horizon/horizon/templatetags/horizon.py +++ b/horizon/horizon/templatetags/horizon.py @@ -61,7 +61,7 @@ def horizon_dashboard_nav(context): if 'request' not in context: return {} dashboard = context['request'].horizon['dashboard'] - if type(dashboard.panels) is dict: + if isinstance(dashboard.panels, dict): panels = copy.copy(dashboard.get_panels()) else: panels = {dashboard.name: dashboard.get_panels()}