[elbe-devel] [PATCH 35/40] pylint: fix do not use `len(SEQUENCE)`

Manuel Traut manut at linutronix.de
Fri Sep 14 13:56:47 CEST 2018


sequences default to true / false if they contain don't contain
elements. It is a performance improvement if the len is not checked, if
just the information is needed, if the sequence contains elements.

Signed-off-by: Manuel Traut <manut at linutronix.de>
---
 elbepack/aptpkgutils.py            | 2 +-
 elbepack/asciidoclog.py            | 2 +-
 elbepack/commands/check_updates.py | 2 +-
 elbepack/commands/db.py            | 2 +-
 elbepack/commands/diff.py          | 4 ++--
 elbepack/commands/init.py          | 4 ++--
 elbepack/commands/parselicence.py  | 6 +++---
 elbepack/commands/pin_versions.py  | 2 +-
 elbepack/commands/setsel.py        | 2 +-
 elbepack/commands/show.py          | 4 ++--
 elbepack/commands/validate.py      | 2 +-
 elbepack/elbexml.py                | 2 +-
 elbepack/filesystem.py             | 2 +-
 elbepack/hdimg.py                  | 2 +-
 elbepack/pkgutils.py               | 2 +-
 elbepack/soapclient.py             | 2 +-
 elbepack/virtapt.py                | 4 ++--
 elbepack/xmlpreprocess.py          | 2 +-
 18 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/elbepack/aptpkgutils.py b/elbepack/aptpkgutils.py
index 5af4830e..9c8b37ce 100644
--- a/elbepack/aptpkgutils.py
+++ b/elbepack/aptpkgutils.py
@@ -32,7 +32,7 @@ def getalldeps(c, pkgname):
     retval = []
     togo = [pkgname]
 
-    while len(togo):
+    while togo:
         pp = togo.pop()
         pkg = c[pp]
 
diff --git a/elbepack/asciidoclog.py b/elbepack/asciidoclog.py
index 0c3b65eb..6fbb2d14 100644
--- a/elbepack/asciidoclog.py
+++ b/elbepack/asciidoclog.py
@@ -75,7 +75,7 @@ class LogBase(object):
 
         ret, output, stderr = command_out_stderr(cmd)
 
-        if len(stderr) != 0:
+        if stderr:
             self.verbatim_start()
             self.print_raw(stderr)
             self.verbatim_end()
diff --git a/elbepack/commands/check_updates.py b/elbepack/commands/check_updates.py
index 7b0274c2..2e5da5a1 100644
--- a/elbepack/commands/check_updates.py
+++ b/elbepack/commands/check_updates.py
@@ -43,7 +43,7 @@ def run_command(argv):
 
     if not opt.skip_validation:
         validation = validate_xml(args[0])
-        if len(validation) != 0:
+        if validation:
             print("xml validation failed. Bailing out")
             for i in validation:
                 print(i)
diff --git a/elbepack/commands/db.py b/elbepack/commands/db.py
index 2faa534c..cb669aca 100644
--- a/elbepack/commands/db.py
+++ b/elbepack/commands/db.py
@@ -10,7 +10,7 @@ from elbepack.dbaction import DbAction
 
 def run_command(argv):
 
-    if not len(argv):
+    if not argv:
         print("elbe db - no action given")
         DbAction.print_actions()
         return
diff --git a/elbepack/commands/diff.py b/elbepack/commands/diff.py
index b5c8749f..dd087b2f 100644
--- a/elbepack/commands/diff.py
+++ b/elbepack/commands/diff.py
@@ -31,7 +31,7 @@ def walk_generated(gen_path, fix_path, exclude):
         if True in [infs_root.startswith(x) for x in exclude]:
             continue
 
-        if len(files) == 0:
+        if not files:
             if not os.path.exists(fix_path + infs_root):
                 print(
                     "empty directory %s only exists in gen image" %
@@ -86,7 +86,7 @@ def walk_fixed(gen_path, fix_path, exclude):
         if True in [infs_root.startswith(x) for x in exclude]:
             continue
 
-        if len(files) == 0:
+        if not files:
             if not os.path.exists(gen_path + infs_root):
                 print(
                     "empty directory %s only exists in fix image" %
diff --git a/elbepack/commands/init.py b/elbepack/commands/init.py
index 0d97b93d..140d9e18 100644
--- a/elbepack/commands/init.py
+++ b/elbepack/commands/init.py
@@ -75,7 +75,7 @@ def run_command(argv):
 
     (opt, args) = oparser.parse_args(argv)
 
-    if len(args) == 0:
+    if not args:
         print("no filename specified")
         oparser.print_help()
         sys.exit(20)
@@ -91,7 +91,7 @@ def run_command(argv):
 
     if not opt.skip_validation:
         validation = validate_xml(args[0])
-        if len(validation) != 0:
+        if validation:
             print("xml validation failed. Bailing out")
             for i in validation:
                 print(i)
diff --git a/elbepack/commands/parselicence.py b/elbepack/commands/parselicence.py
index 372af83c..50deedce 100644
--- a/elbepack/commands/parselicence.py
+++ b/elbepack/commands/parselicence.py
@@ -82,7 +82,7 @@ class license_dep5_to_spdx (dict):
 
     def map_lic(self, pkgname, licenses, errors):
         if pkgname in self.perpackage_override:
-            if len(self.perpackage_override[pkgname]) > 0:
+            if self.perpackage_override[pkgname]:
                 return self.perpackage_override[pkgname]
 
         retval = []
@@ -211,7 +211,7 @@ def run_command(argv):
                 ll = sp.append('license')
                 ll.et.text = l
 
-            if len(mapped_lics) == 0:
+            if not mapped_lics:
                 errors.append(
                     'empty mapped licenses in package "%s"' %
                     pkg_name)
@@ -237,7 +237,7 @@ def run_command(argv):
                     ll = nomos_node.append('license')
                     ll.et.text = l
 
-        if len(errors) > 0:
+        if errors:
             for e in errors:
                 ee = pkg.append('error')
                 ee.et.text = e
diff --git a/elbepack/commands/pin_versions.py b/elbepack/commands/pin_versions.py
index 3444f2c7..e5eb13b5 100644
--- a/elbepack/commands/pin_versions.py
+++ b/elbepack/commands/pin_versions.py
@@ -31,7 +31,7 @@ def run_command(argv):
 
     if not opt.skip_validation:
         validation = validate_xml(args[0])
-        if len(validation) != 0:
+        if validation:
             print("xml validation failed. Bailing out")
             for i in validation:
                 print(i)
diff --git a/elbepack/commands/setsel.py b/elbepack/commands/setsel.py
index 13acb30b..141b05b1 100644
--- a/elbepack/commands/setsel.py
+++ b/elbepack/commands/setsel.py
@@ -19,7 +19,7 @@ def parse_selections(fname):
     sels = []
 
     for l in fp.readlines():
-        if len(l) == 0:
+        if not l:
             continue
         if l[0] == '#':
             continue
diff --git a/elbepack/commands/show.py b/elbepack/commands/show.py
index 59173917..e1076d80 100644
--- a/elbepack/commands/show.py
+++ b/elbepack/commands/show.py
@@ -31,7 +31,7 @@ def run_command(argv):
 
     (opt, args) = oparser.parse_args(argv)
 
-    if len(args) == 0:
+    if not args:
         print("No Filename specified")
         oparser.print_help()
         sys.exit(20)
@@ -44,7 +44,7 @@ def run_command(argv):
     try:
         if not opt.skip_validation:
             validation = validate_xml(args[0])
-            if len(validation) != 0:
+            if validation:
                 print("xml validation failed. Bailing out")
                 for i in validation:
                     print(i)
diff --git a/elbepack/commands/validate.py b/elbepack/commands/validate.py
index 2e254b1f..dc711506 100644
--- a/elbepack/commands/validate.py
+++ b/elbepack/commands/validate.py
@@ -31,7 +31,7 @@ def run_command(argv):
         sys.exit(20)
 
     validation = validate_xml(args[0])
-    if len(validation):
+    if validation:
         print("validation failed")
         for i in validation:
             print(i)
diff --git a/elbepack/elbexml.py b/elbepack/elbexml.py
index 856325ec..4eb26b9f 100644
--- a/elbepack/elbexml.py
+++ b/elbepack/elbexml.py
@@ -62,7 +62,7 @@ class ElbeXML(object):
             url_validation=ValidationMode.NO_CHECK):
         if not skip_validate:
             validation = validate_xml(fname)
-            if len(validation) != 0:
+            if validation:
                 raise ValidationError(validation)
 
         self.xml = etree(fname)
diff --git a/elbepack/filesystem.py b/elbepack/filesystem.py
index e7ce208d..c0089173 100644
--- a/elbepack/filesystem.py
+++ b/elbepack/filesystem.py
@@ -193,7 +193,7 @@ class Filesystem(object):
             striplen = len(dirname)
         for dirpath, dirnames, filenames in os.walk(dirname):
             subpath = dirpath[striplen:]
-            if len(subpath) == 0:
+            if not subpath:
                 subpath = "/"
 
             deldirs = []
diff --git a/elbepack/hdimg.py b/elbepack/hdimg.py
index 058e201f..843c5f85 100644
--- a/elbepack/hdimg.py
+++ b/elbepack/hdimg.py
@@ -612,7 +612,7 @@ def do_hdimg(outf, xml, target, rfs, grub_version, grub_fw_type=None):
     for l in reversed(fslist):
         outf.do('mkdir -p "%s"' % os.path.join(fspath, l.id))
         outf.do('mkdir -p "%s"' % rfs.fname('') + l.mountpoint)
-        if len(rfs.listdir(l.mountpoint)) > 0:
+        if rfs.listdir(l.mountpoint):
             outf.do('mv "%s"/* "%s"' % (rfs.fname(l.mountpoint), os.path.join(
                 fspath, l.id)), allow_fail=True)
 
diff --git a/elbepack/pkgutils.py b/elbepack/pkgutils.py
index 76fc7887..0a68a819 100644
--- a/elbepack/pkgutils.py
+++ b/elbepack/pkgutils.py
@@ -246,7 +246,7 @@ def download_pkg(prj,
         except CommandError:
             raise NoKinitrdException("couldn't download package %s" % package)
 
-        if len(sha256) > 0:
+        if sha256:
             m = hashlib.sha256()
             with open(dest, "rb") as f:
                 buf = f.read(65536)
diff --git a/elbepack/soapclient.py b/elbepack/soapclient.py
index 953bc1f4..4eedca3a 100644
--- a/elbepack/soapclient.py
+++ b/elbepack/soapclient.py
@@ -696,7 +696,7 @@ class ShutdownInitvmAction(ClientAction):
         ClientAction.__init__(self, node)
 
     def execute(self, client, _opt, args):
-        if len(args) != 0:
+        if args:
             print("usage: elbe control shutdown_initvm", file=sys.stderr)
             sys.exit(20)
 
diff --git a/elbepack/virtapt.py b/elbepack/virtapt.py
index 3d148041..cb2c9edf 100644
--- a/elbepack/virtapt.py
+++ b/elbepack/virtapt.py
@@ -241,7 +241,7 @@ class VirtApt(object):
 
         deps = [lookup_uri(self, d, target_pkg)]
         togo = [target_pkg]
-        while len(togo):
+        while togo:
             pp = togo.pop()
             try:
                 pkg= self.cache[pp]
@@ -260,7 +260,7 @@ class VirtApt(object):
                 print("couldnt get candidate: %s" % pkg)
             else:
                 for p in getdeps(c):
-                    if len([y for y in deps if y[0] == p]):
+                    if [y for y in deps if y[0] == p]:
                         continue
                     if p != target_pkg and p == pp:
                         continue
diff --git a/elbepack/xmlpreprocess.py b/elbepack/xmlpreprocess.py
index e1456b4d..6ec70c37 100644
--- a/elbepack/xmlpreprocess.py
+++ b/elbepack/xmlpreprocess.py
@@ -52,7 +52,7 @@ def xmlpreprocess(fname, output, variants=None):
                 # active variants.
                 intersect = variants.intersection(tag_variants)
 
-                if len(intersect):
+                if intersect:
                     # variant is wanted, keep it and remove the variant
                     # attribute
                     tag.attrib.pop('variant')
-- 
2.19.0.rc2




More information about the elbe-devel mailing list