[09/11] dpdk-pmdinfo: do not use len(x) to test for empty
diff mbox series

Message ID 20200906013133.26360-10-stephen@networkplumber.org
State New
Delegated to: Thomas Monjalon
Headers show
Series
  • Python script updates
Related show

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Sept. 6, 2020, 1:31 a.m. UTC
This fixes the following python lint warnings.
usertools/dpdk-pmdinfo.py:188:11: C1801: Do not use `len(SEQUENCE)` to determine if a sequence is empty (len-as-condition)
usertools/dpdk-pmdinfo.py:196:21: C1801: Do not use `len(SEQUENCE)` to determine if a sequence is empty (len-as-condition)
usertools/dpdk-pmdinfo.py:302:11: C1801: Do not use `len(SEQUENCE)` to determine if a sequence is empty (len-as-condition)

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 usertools/dpdk-pmdinfo.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Bruce Richardson Sept. 7, 2020, 9:03 a.m. UTC | #1
On Sat, Sep 05, 2020 at 06:31:31PM -0700, Stephen Hemminger wrote:
> This fixes the following python lint warnings.
> usertools/dpdk-pmdinfo.py:188:11: C1801: Do not use `len(SEQUENCE)` to determine if a sequence is empty (len-as-condition)
> usertools/dpdk-pmdinfo.py:196:21: C1801: Do not use `len(SEQUENCE)` to determine if a sequence is empty (len-as-condition)
> usertools/dpdk-pmdinfo.py:302:11: C1801: Do not use `len(SEQUENCE)` to determine if a sequence is empty (len-as-condition)
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  usertools/dpdk-pmdinfo.py | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py
> index d746348f1415..632271e2f1d2 100755
> --- a/usertools/dpdk-pmdinfo.py
> +++ b/usertools/dpdk-pmdinfo.py
> @@ -185,7 +185,7 @@ def findDate(self, content):
>          return None
>  
>      def parse(self):
> -        if len(self.contents) < 1:
> +        if not len(self.contents):

Does an empty sequence not directly resolve to false in python? If so, the
len should be removable and just use "if not self.contents:"

>              print("data/%s-pci.ids not found" % self.date)
>          else:
>              vendorID = ""
> @@ -193,7 +193,7 @@ def parse(self):
>              for l in self.contents:
>                  if l[0] == "#":
>                      continue
> -                elif len(l.strip()) == 0:
> +                elif not l.strip():
>                      continue
>                  else:
>                      if l.find("\t\t") == 0:
> @@ -299,7 +299,7 @@ def parse_pmd_info_string(self, mystring):
>              except KeyError:
>                  continue
>  
> -        if len(pmdinfo["pci_ids"]) != 0:
> +        if pmdinfo["pci_ids"]:
>              print("PMD HW SUPPORT:")
>              if pcidb is not None:
>                  self.pretty_print_pmdinfo(pmdinfo)
> -- 
> 2.27.0
>
Stephen Hemminger Sept. 7, 2020, 5:20 p.m. UTC | #2
On Mon, 7 Sep 2020 10:03:43 +0100
Bruce Richardson <bruce.richardson@intel.com> wrote:

> Does an empty sequence not directly resolve to false in python? If so, the
> len should be removable and just use "if not self.contents:"

Yes, len should be removed there

Patch
diff mbox series

diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py
index d746348f1415..632271e2f1d2 100755
--- a/usertools/dpdk-pmdinfo.py
+++ b/usertools/dpdk-pmdinfo.py
@@ -185,7 +185,7 @@  def findDate(self, content):
         return None
 
     def parse(self):
-        if len(self.contents) < 1:
+        if not len(self.contents):
             print("data/%s-pci.ids not found" % self.date)
         else:
             vendorID = ""
@@ -193,7 +193,7 @@  def parse(self):
             for l in self.contents:
                 if l[0] == "#":
                     continue
-                elif len(l.strip()) == 0:
+                elif not l.strip():
                     continue
                 else:
                     if l.find("\t\t") == 0:
@@ -299,7 +299,7 @@  def parse_pmd_info_string(self, mystring):
             except KeyError:
                 continue
 
-        if len(pmdinfo["pci_ids"]) != 0:
+        if pmdinfo["pci_ids"]:
             print("PMD HW SUPPORT:")
             if pcidb is not None:
                 self.pretty_print_pmdinfo(pmdinfo)