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

Bruce Richardson bruce.richardson at intel.com
Mon Sep 7 11:03:43 CEST 2020


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 at 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
> 


More information about the dev mailing list