Avoid using `len(x)` to check if x is empty

Bug #1538518 reported by Illia Khudoshyn
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Rally
Fix Released
Wishlist
Steve Wilkerson

Bug Description

`len()` is used to check if collection (e.g., a dict, list, set, etc.) has items. As collections have a boolean representation too, it is better to directly check for true / false.

rally/common/utils.py
rally/task/utils.py
rally/task/validation.py
tests/unit/doc/test_specs.py

Changed in rally:
status: New → Triaged
importance: Undecided → Wishlist
Changed in rally:
assignee: nobody → Steve Wilkerson (sw5822)
Changed in rally:
status: Triaged → In Progress
Changed in nova:
assignee: nobody → Ren Qiaowei (qiaowei-ren)
status: New → In Progress
Changed in swift:
assignee: nobody → Ren Qiaowei (qiaowei-ren)
status: New → In Progress
Changed in glance:
assignee: nobody → Ren Qiaowei (qiaowei-ren)
status: New → In Progress
Changed in cinder:
assignee: nobody → Ren Qiaowei (qiaowei-ren)
status: New → In Progress
Changed in ceilometer:
assignee: nobody → Ren Qiaowei (qiaowei-ren)
status: New → In Progress
Changed in neutron:
assignee: nobody → Ren Qiaowei (qiaowei-ren)
status: New → In Progress
description: updated
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to swift (master)

Fix proposed to branch: master
Review: https://review.openstack.org/276996

Revision history for this message
Julien Danjou (jdanjou) wrote :

I don't think spamming multiple projects with false bugs is a good idea. Please stop.

no longer affects: ceilometer
Assaf Muller (amuller)
no longer affects: neutron
Revision history for this message
Sean McGinnis (sean-mcginnis) wrote :

I have to agree with Julien.

no longer affects: cinder
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to rally (master)

Reviewed: https://review.openstack.org/276886
Committed: https://git.openstack.org/cgit/openstack/rally/commit/?id=efd641caf0ad0bba0c6ad0993a5b65d08078966d
Submitter: Jenkins
Branch: master

commit efd641caf0ad0bba0c6ad0993a5b65d08078966d
Author: Steve Wilkerson <email address hidden>
Date: Fri Feb 5 13:38:51 2016 -0600

    Use booleans to check for empty lists

    Changed from checking for empty collections with
    len(list) to checking the boolean value of the list
    instead

    Closes-Bug: #1538518
    Change-Id: Ib601a83b8b6e19ab78690f8ca2834e7ef622cb9b

Changed in rally:
status: In Progress → Fix Released
clayg (clay-gerrard)
Changed in swift:
importance: Undecided → Wishlist
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on swift (master)

Change abandoned by Ren Qiaowei (<email address hidden>) on branch: master
Review: https://review.openstack.org/276996

description: updated
no longer affects: glance
no longer affects: nova
no longer affects: swift
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.