Browse Source

pylint: fix len-as-condition warning

Change-Id: Ib89c1854ad42b96e4caf281160d568fe98430afe
Akihiro Motoki 4 months ago
parent
commit
c076db20c8

+ 0
- 1
.pylintrc View File

@@ -48,7 +48,6 @@ disable=
48 48
  expression-not-assigned,
49 49
  global-statement,
50 50
  invalid-name,
51
- len-as-condition,
52 51
  line-too-long,
53 52
  misplaced-comparison-constant,
54 53
  missing-docstring,

+ 3
- 3
horizon/base.py View File

@@ -519,7 +519,7 @@ class Dashboard(Registry, HorizonComponent):
519 519
                 panel_groups.append((panel_group.slug, panel_group))
520 520
 
521 521
         # Deal with leftovers (such as add-on registrations)
522
-        if len(registered):
522
+        if registered:
523 523
             slugs = [panel.slug for panel in registered.values()]
524 524
             new_group = PanelGroup(self,
525 525
                                    slug="other",
@@ -769,7 +769,7 @@ class Site(Registry, HorizonComponent):
769 769
                 dashboard = self._registered(item)
770 770
                 dashboards.append(dashboard)
771 771
                 registered.pop(dashboard.__class__)
772
-            if len(registered):
772
+            if registered:
773 773
                 extra = sorted(registered.values())
774 774
                 dashboards.extend(extra)
775 775
             return dashboards
@@ -785,7 +785,7 @@ class Site(Registry, HorizonComponent):
785 785
         """
786 786
         if self.default_dashboard:
787 787
             return self._registered(self.default_dashboard)
788
-        elif len(self._registry):
788
+        elif self._registry:
789 789
             return self.get_dashboards()[0]
790 790
         else:
791 791
             raise NotRegistered("No dashboard modules have been registered.")

+ 1
- 1
horizon/middleware/operation_log.py View File

@@ -182,7 +182,7 @@ class OperationLogMiddleware(object):
182 182
 
183 183
         # when a file uploaded (E.g create image)
184 184
         files = request.FILES.values()
185
-        if len(list(files)) > 0:
185
+        if list(files):
186 186
             filenames = ', '.join(
187 187
                 [up_file.name for up_file in files])
188 188
             params['file_name'] = filenames

+ 1
- 1
horizon/tables/base.py View File

@@ -496,7 +496,7 @@ class Column(html.HTMLElement):
496 496
         data = [self.get_raw_data(datum) for datum in self.table.data]
497 497
         data = [raw_data for raw_data in data if raw_data is not None]
498 498
 
499
-        if len(data):
499
+        if data:
500 500
             try:
501 501
                 summation = summation_function(data)
502 502
                 for filter_func in self.filters:

+ 1
- 1
horizon/utils/babel_extract_angular.py View File

@@ -123,7 +123,7 @@ class AngularGettextHTMLParser(html_parser.HTMLParser):
123 123
 
124 124
     def handle_endtag(self, tag):
125 125
         if self.in_translate:
126
-            if len(self.inner_tags) > 0:
126
+            if self.inner_tags:
127 127
                 tag = self.inner_tags.pop()
128 128
                 self.data += "</%s>" % tag
129 129
                 return

+ 1
- 1
horizon/workflows/base.py View File

@@ -905,7 +905,7 @@ class Workflow(html.HTMLElement):
905 905
 
906 906
     def verify_integrity(self):
907 907
         provided_keys = self.contributions | set(self.context_seed.keys())
908
-        if len(self.depends_on - provided_keys):
908
+        if self.depends_on - provided_keys:
909 909
             raise exceptions.NotAvailable(
910 910
                 _("The current user has insufficient permission to complete "
911 911
                   "the requested task."))

+ 1
- 1
openstack_dashboard/api/base.py View File

@@ -258,7 +258,7 @@ class QuotaSet(Sequence):
258 258
 
259 259
     def get(self, key, default=None):
260 260
         match = [quota for quota in self.items if quota.name == key]
261
-        return match.pop() if len(match) else Quota(key, default)
261
+        return match.pop() if match else Quota(key, default)
262 262
 
263 263
     def add(self, other):
264 264
         return self.__add__(other)

+ 1
- 1
openstack_dashboard/api/keystone.py View File

@@ -634,7 +634,7 @@ def group_list(request, domain=None, project=None, user=None, filters=None):
634 634
         project_groups = []
635 635
         for group in groups:
636 636
             roles = roles_for_group(request, group=group.id, project=project)
637
-            if roles and len(roles) > 0:
637
+            if roles:
638 638
                 project_groups.append(group)
639 639
         groups = project_groups
640 640
     return groups

+ 2
- 2
openstack_dashboard/api/nova.py View File

@@ -602,14 +602,14 @@ def server_list_paged(request,
602 602
         servers = [Server(s, request)
603 603
                    for s in nova_client.servers.list(detailed, search_opts)]
604 604
         if view_marker == 'possibly_deleted':
605
-            if len(servers) == 0:
605
+            if not servers:
606 606
                 view_marker = 'head_deleted'
607 607
                 search_opts['sort_dir'] = 'desc'
608 608
                 reversed_order = False
609 609
                 servers = [Server(s, request)
610 610
                            for s in nova_client.servers.list(detailed,
611 611
                                                              search_opts)]
612
-            if len(servers) == 0:
612
+            if not servers:
613 613
                 view_marker = 'tail_deleted'
614 614
                 search_opts['sort_dir'] = 'asc'
615 615
                 reversed_order = True

+ 2
- 2
openstack_dashboard/api/rest/keystone.py View File

@@ -56,7 +56,7 @@ class Users(generic.View):
56 56
 
57 57
         filters = rest_utils.parse_filters_kwargs(request,
58 58
                                                   self.client_keywords)[0]
59
-        if len(filters) == 0:
59
+        if not filters:
60 60
             filters = None
61 61
 
62 62
         result = api.keystone.user_list(
@@ -420,7 +420,7 @@ class Projects(generic.View):
420 420
 
421 421
         filters = rest_utils.parse_filters_kwargs(request,
422 422
                                                   self.client_keywords)[0]
423
-        if len(filters) == 0:
423
+        if not filters:
424 424
             filters = None
425 425
 
426 426
         paginate = request.GET.get('paginate') == 'true'

+ 1
- 1
openstack_dashboard/contrib/developer/profiler/api.py View File

@@ -89,7 +89,7 @@ def list_traces(request):
89 89
 def get_trace(request, trace_id):
90 90
     def rec(_data, level=0):
91 91
         _data['level'] = level
92
-        _data['is_leaf'] = not len(_data['children'])
92
+        _data['is_leaf'] = not _data['children']
93 93
         _data['visible'] = True
94 94
         _data['childrenVisible'] = True
95 95
         finished = _data['info']['finished']

+ 1
- 2
openstack_dashboard/dashboards/admin/info/tables.py View File

@@ -59,8 +59,7 @@ def show_endpoints(datanum):
59 59
     if 'endpoints' in datanum:
60 60
         template_name = 'admin/info/_cell_endpoints_v2.html'
61 61
         context = None
62
-        if (len(datanum['endpoints']) > 0 and
63
-                "publicURL" in datanum['endpoints'][0]):
62
+        if (datanum['endpoints'] and "publicURL" in datanum['endpoints'][0]):
64 63
             context = datanum['endpoints'][0]
65 64
         else:
66 65
             # this is a keystone v3 version of endpoints

+ 1
- 1
openstack_dashboard/dashboards/admin/networks/forms.py View File

@@ -238,7 +238,7 @@ class CreateNetwork(forms.SelfHandlingForm):
238 238
             network_type_choices = [
239 239
                 (net_type, self.provider_types[net_type]['display_name'])
240 240
                 for net_type in supported_provider_types]
241
-            if len(network_type_choices) == 0:
241
+            if not network_type_choices:
242 242
                 self._hide_provider_network_type()
243 243
             else:
244 244
                 self.fields['network_type'].choices = network_type_choices

+ 1
- 1
openstack_dashboard/dashboards/identity/domains/workflows.py View File

@@ -368,7 +368,7 @@ class UpdateDomain(workflows.Workflow):
368 368
                 ]
369 369
                 admin_role_ids = [role for role in current_role_ids
370 370
                                   if role in available_admin_role_ids]
371
-                if len(admin_role_ids):
371
+                if admin_role_ids:
372 372
                     removing_admin = any([role in current_role_ids
373 373
                                           for role in admin_role_ids])
374 374
                 else:

+ 1
- 2
openstack_dashboard/dashboards/identity/groups/views.py View File

@@ -54,8 +54,7 @@ class IndexView(tables.DataTableView):
54 54
             # selected, then search criteria must be provided and
55 55
             # return an empty list
56 56
             filter_first = getattr(settings, 'FILTER_DATA_FIRST', {})
57
-            if filter_first.get('identity.groups', False) \
58
-                    and len(filters) == 0:
57
+            if filter_first.get('identity.groups', False) and not filters:
59 58
                 self._needs_filter_first = True
60 59
                 return groups
61 60
 

+ 1
- 2
openstack_dashboard/dashboards/identity/projects/views.py View File

@@ -96,8 +96,7 @@ class IndexView(tables.DataTableView):
96 96
             # selected, then search criteria must be provided and
97 97
             # return an empty list
98 98
             filter_first = getattr(settings, 'FILTER_DATA_FIRST', {})
99
-            if filter_first.get('identity.projects', False) and len(
100
-                    filters) == 0:
99
+            if filter_first.get('identity.projects', False) and not filters:
101 100
                 self._needs_filter_first = True
102 101
                 self._more = False
103 102
                 return tenants

+ 1
- 1
openstack_dashboard/dashboards/identity/projects/workflows.py View File

@@ -752,7 +752,7 @@ class UpdateProject(workflows.Workflow):
752 752
                                     if role.name.lower() in _admin_roles]
753 753
         admin_roles = [role for role in current_role_ids
754 754
                        if role in available_admin_role_ids]
755
-        if len(admin_roles):
755
+        if admin_roles:
756 756
             removing_admin = any([role in current_role_ids
757 757
                                   for role in admin_roles])
758 758
         else:

+ 1
- 1
openstack_dashboard/dashboards/identity/roles/views.py View File

@@ -52,7 +52,7 @@ class IndexView(tables.DataTableView):
52 52
             # selected, then search criteria must be provided
53 53
             # and return an empty list
54 54
             filter_first = getattr(settings, 'FILTER_DATA_FIRST', {})
55
-            if filter_first.get('identity.roles', False) and len(filters) == 0:
55
+            if filter_first.get('identity.roles', False) and not filters:
56 56
                 self._needs_filter_first = True
57 57
                 return roles
58 58
 

+ 1
- 1
openstack_dashboard/dashboards/identity/users/views.py View File

@@ -68,7 +68,7 @@ class IndexView(tables.DataTableView):
68 68
             # selected, then search criteria must be provided
69 69
             # and return an empty list
70 70
             filter_first = getattr(settings, 'FILTER_DATA_FIRST', {})
71
-            if filter_first.get('identity.users', False) and len(filters) == 0:
71
+            if filter_first.get('identity.users', False) and not filters:
72 72
                 self._needs_filter_first = True
73 73
                 return users
74 74
 

+ 2
- 2
openstack_dashboard/dashboards/project/cgroups/forms.py View File

@@ -149,7 +149,7 @@ class CreateSnapshotForm(forms.SelfHandlingForm):
149 149
             else:
150 150
                 search_opts = {'consistentcygroup_id': data['cgroup_id']}
151 151
                 volumes = cinder.volume_list(request, search_opts=search_opts)
152
-                if len(volumes) == 0:
152
+                if not volumes:
153 153
                     msg = _('Unable to create snapshot. Consistency group '
154 154
                             'must contain volumes.')
155 155
 
@@ -208,7 +208,7 @@ class CloneCGroupForm(forms.SelfHandlingForm):
208 208
 
209 209
             search_opts = {'consistentcygroup_id': data['cgroup_id']}
210 210
             volumes = cinder.volume_list(request, search_opts=search_opts)
211
-            if len(volumes) == 0:
211
+            if not volumes:
212 212
                 msg = _('Unable to clone empty consistency group.')
213 213
 
214 214
             exceptions.handle(request,

+ 1
- 1
openstack_dashboard/dashboards/project/instances/forms.py View File

@@ -347,7 +347,7 @@ class AttachInterface(forms.SelfHandlingForm):
347 347
 
348 348
         choices = [('network', _("by Network (and IP address)"))]
349 349
         ports = instance_utils.port_field_data(request, with_network=True)
350
-        if len(ports) > 0:
350
+        if ports:
351 351
             self.fields['port'].choices = ports
352 352
             choices.append(('port', _("by Port")))
353 353
 

+ 5
- 5
openstack_dashboard/dashboards/project/networks/workflows.py View File

@@ -235,10 +235,10 @@ class CreateSubnetInfoAction(workflows.Action):
235 235
             # Populate data-fields for switching the prefixlen field
236 236
             # when user selects a subnetpool other than
237 237
             # "Provider default pool"
238
-            for (id, name) in self.fields['subnetpool'].choices:
239
-                if not len(id):
238
+            for (id_, name) in self.fields['subnetpool'].choices:
239
+                if not id_:
240 240
                     continue
241
-                key = 'data-subnetpool-' + id
241
+                key = 'data-subnetpool-' + id_
242 242
                 self.fields['prefixlen'].widget.attrs[key] = \
243 243
                     _('Network Mask')
244 244
         else:
@@ -555,9 +555,9 @@ class CreateNetwork(workflows.Workflow):
555 555
                 params['gateway_ip'] = None
556 556
             elif data['gateway_ip']:
557 557
                 params['gateway_ip'] = data['gateway_ip']
558
-            if 'subnetpool' in data and len(data['subnetpool']):
558
+            if 'subnetpool' in data and data['subnetpool']:
559 559
                 params['subnetpool_id'] = data['subnetpool']
560
-                if 'prefixlen' in data and len(data['prefixlen']):
560
+                if 'prefixlen' in data and data['prefixlen']:
561 561
                     params['prefixlen'] = data['prefixlen']
562 562
 
563 563
             self._setup_subnet_parameters(params, data)

+ 2
- 2
openstack_dashboard/dashboards/project/volume_groups/forms.py View File

@@ -136,7 +136,7 @@ class CreateSnapshotForm(forms.SelfHandlingForm):
136 136
                 search_opts = {'group_id': group_id}
137 137
                 volumes = cinder.volume_list(request,
138 138
                                              search_opts=search_opts)
139
-                if len(volumes) == 0:
139
+                if not volumes:
140 140
                     msg = _('Unable to create snapshot. '
141 141
                             'group must contain volumes.')
142 142
 
@@ -190,7 +190,7 @@ class CloneGroupForm(forms.SelfHandlingForm):
190 190
 
191 191
             search_opts = {'group_id': group_id}
192 192
             volumes = cinder.volume_list(request, search_opts=search_opts)
193
-            if len(volumes) == 0:
193
+            if not volumes:
194 194
                 msg = _('Unable to clone empty group.')
195 195
 
196 196
             exceptions.handle(request,

Loading…
Cancel
Save