[elbe-devel] [PATCH 30/40] pylint: remove unneeded else

Torben Hohn torben.hohn at linutronix.de
Thu Sep 20 13:39:55 CEST 2018


On Thu, Sep 20, 2018 at 01:39:13PM +0200, Torben Hohn wrote:
> On Fri, Sep 14, 2018 at 01:56:42PM +0200, Manuel Traut wrote:
> > else after return is not needed, remove it to make pylint happy,
> >   however IMHO it doesn't improve readability of the code, but
> >   that's maybe a personal thing.
> 
> hmm... i also thought it doesnt improve readability.
> but after looking at it, i think it does in a few cases.
> 
> one needs to make sure though, that the final return statement is
> the "regular" case.

errm.... forgot:

Reviewed-by: Torben Hohn <torben.hohn at linutronix.de>

> 
> > 
> > Signed-off-by: Manuel Traut <manut at linutronix.de>
> > ---
> >  elbepack/aptpkgutils.py |  4 ++--
> >  elbepack/db.py          |  4 ++--
> >  elbepack/elbeproject.py | 12 ++++++------
> >  elbepack/elbexml.py     |  9 +++------
> >  elbepack/fstab.py       |  4 ++--
> >  elbepack/licencexml.py  |  4 ++--
> >  elbepack/pkgutils.py    |  5 +----
> >  elbepack/repomanager.py | 19 +++++++------------
> >  elbepack/templates.py   |  4 ++--
> >  elbepack/treeutils.py   | 16 ++++++++--------
> >  10 files changed, 35 insertions(+), 46 deletions(-)
> > 
> > diff --git a/elbepack/aptpkgutils.py b/elbepack/aptpkgutils.py
> > index 836ebaa6..5af4830e 100644
> > --- a/elbepack/aptpkgutils.py
> > +++ b/elbepack/aptpkgutils.py
> > @@ -58,8 +58,8 @@ def pkgstate(pkg):
> >          return UPGRADABLE
> >      elif pkg.is_installed:
> >          return INSTALLED
> > -    else:
> > -        return NOTINSTALLED
> > +
> > +    return NOTINSTALLED
> >  
> >  
> >  def pkgorigin(pkg):
> > diff --git a/elbepack/db.py b/elbepack/db.py
> > index bf1dba3f..7ce615d5 100644
> > --- a/elbepack/db.py
> > +++ b/elbepack/db.py
> > @@ -553,8 +553,8 @@ class ElbeDB(object):
> >  
> >              if p.owner_id is None:
> >                  return None
> > -            else:
> > -                return int(p.owner_id)
> > +
> > +            return int(p.owner_id)
> >  
> >      def set_project_version(self, builddir, new_version=None):
> >          if new_version == "":
> > diff --git a/elbepack/elbeproject.py b/elbepack/elbeproject.py
> > index 1469aff6..98c0c63a 100644
> > --- a/elbepack/elbeproject.py
> > +++ b/elbepack/elbeproject.py
> > @@ -733,14 +733,14 @@ class ElbeProject (object):
> >                                             "etc", "elbe_version")
> >              if os.path.isfile(elbeversionpath):
> >                  return True
> > -            else:
> > -                self.log.printo("%s exists, but it does not have "
> > -                                "an etc/elbe_version file." % self.chrootpath)
> > -                # Apparently we do not have a functional build environment
> > -                return False
> > -        else:
> > +
> > +            self.log.printo("%s exists, but it does not have "
> > +                            "an etc/elbe_version file." % self.chrootpath)
> > +            # Apparently we do not have a functional build environment
> >              return False
> >  
> > +        return False
> > +
> >      def set_xml(self, xmlpath):
> >          # Use supplied XML file, if given, otherwise change to source.xml
> >          if not xmlpath:
> > diff --git a/elbepack/elbexml.py b/elbepack/elbexml.py
> > index f1d3729e..856325ec 100644
> > --- a/elbepack/elbexml.py
> > +++ b/elbepack/elbexml.py
> > @@ -83,8 +83,7 @@ class ElbeXML(object):
> >      def text(self, txt, key=None):
> >          if key:
> >              return self.xml.text(txt, default=self.defs, key=key)
> > -        else:
> > -            return self.xml.text(txt)
> > +        return self.xml.text(txt)
> >  
> >      def has(self, path):
> >          return self.xml.has(path)
> > @@ -361,8 +360,7 @@ class ElbeXML(object):
> >      def get_initvm_codename(self):
> >          if self.has("initvm/suite"):
> >              return self.text("initvm/suite")
> > -        else:
> > -            return None
> > +        return None
> >  
> >      def set_cdrom_mirror(self, abspath):
> >          mirror = self.node("project/mirror")
> > @@ -382,5 +380,4 @@ class ElbeXML(object):
> >      def get_elbe_version(self):
> >          if self.has('elbe_version'):
> >              return self.text('elbe_version')
> > -        else:
> > -            return "no version"
> > +        return "no version"
> > diff --git a/elbepack/fstab.py b/elbepack/fstab.py
> > index 7a1ef478..5e9bb8de 100644
> > --- a/elbepack/fstab.py
> > +++ b/elbepack/fstab.py
> > @@ -34,8 +34,8 @@ def get_devicelabel(xml, node):
> >      if node.text("fs/type") == "ubifs":
> >          return "ubi %s:%s" % (get_mtdnum(xml, node.text("label")),
> >                                node.text("label"))
> > -    else:
> > -        return "LABEL=" + node.text("label")
> > +
> > +    return "LABEL=" + node.text("label")
> >  
> >  
> >  class mountpoint_dict (dict):
> > diff --git a/elbepack/licencexml.py b/elbepack/licencexml.py
> > index 9c277ff5..6324fe4f 100644
> > --- a/elbepack/licencexml.py
> > +++ b/elbepack/licencexml.py
> > @@ -31,8 +31,8 @@ def do_heuristics(fp):
> >  
> >      if num_licenses > 0:
> >          return c
> > -    else:
> > -        return None
> > +
> > +    return None
> >  
> >  
> >  def get_heuristics_license_list(c):
> > diff --git a/elbepack/pkgutils.py b/elbepack/pkgutils.py
> > index 92bbdb0d..76fc7887 100644
> > --- a/elbepack/pkgutils.py
> > +++ b/elbepack/pkgutils.py
> > @@ -187,10 +187,7 @@ def get_uri(prj, defs, arch, target_pkg, incl_deps=False):
> >          ret = v.get_uri(target_pkg, incl_deps)
> >          return ret
> >  
> > -    else:
> > -        return get_uri_nonvirtapt(apt_sources, target_pkg, arch)
> > -
> > -    return [(target_pkg, "nonexistent://" + target_pkg, "")]
> > +    return get_uri_nonvirtapt(apt_sources, target_pkg, arch)
> >  
> >  
> >  def get_dsc_size(fname):
> > diff --git a/elbepack/repomanager.py b/elbepack/repomanager.py
> > index d7540bf4..4e37daeb 100644
> > --- a/elbepack/repomanager.py
> > +++ b/elbepack/repomanager.py
> > @@ -41,17 +41,12 @@ class RepoAttributes(object):
> >  
> >          if other.codename != self.codename:
> >              return [self, other]
> > -        else:
> > -            assert self.mirror == other.mirror
> > -            ret_arch = self.arch.union(other.arch)
> > -            ret_comp = self.components.union(other.components)
> >  
> > -            return [
> > -                RepoAttributes(
> > -                    self.codename,
> > -                    ret_arch,
> > -                    ret_comp,
> > -                    self.mirror)]
> > +        assert self.mirror == other.mirror
> > +        ret_arch = self.arch.union(other.arch)
> > +        ret_comp = self.components.union(other.components)
> > +
> > +        return [RepoAttributes(self.codename, ret_arch, ret_comp, self.mirror)]
> >  
> >  
> >  class RepoBase(object):
> > @@ -100,8 +95,8 @@ class RepoBase(object):
> >          if self.maxsize:
> >              volname = os.path.join(self.vol_path, "vol%02d" % volume)
> >              return Filesystem(volname)
> > -        else:
> > -            return Filesystem(self.vol_path)
> > +
> > +        return Filesystem(self.vol_path)
> >  
> >      def new_repo_volume(self):
> >          self.volume_count += 1
> > diff --git a/elbepack/templates.py b/elbepack/templates.py
> > index 8552595c..6d902278 100644
> > --- a/elbepack/templates.py
> > +++ b/elbepack/templates.py
> > @@ -26,8 +26,8 @@ def template(fname, d, linebreak=False):
> >                  filename=fname,
> >                  preprocessor=fix_linebreak_escapes).render(
> >                  **d)
> > -        else:
> > -            return Template(filename=fname).render(**d)
> > +
> > +        return Template(filename=fname).render(**d)
> >      except BaseException:
> >          print(exceptions.text_error_template().render())
> >          raise
> > diff --git a/elbepack/treeutils.py b/elbepack/treeutils.py
> > index 383f80e2..8ba635d8 100644
> > --- a/elbepack/treeutils.py
> > +++ b/elbepack/treeutils.py
> > @@ -46,10 +46,10 @@ class ebase(object):
> >              default = args["default"]
> >              if isinstance(default, str):
> >                  return default
> > -            else:
> > -                return default[args["key"]]
> > -        else:
> > -            return el.text
> > +
> > +            return default[args["key"]]
> > +
> > +        return el.text
> >  
> >      @property
> >      def tag(self):
> > @@ -89,8 +89,8 @@ class elem(ebase):
> >          retval = self.et.find("./" + tag)
> >          if retval is not None:
> >              return elem(retval)
> > -        else:
> > -            return elem(SubElement(self.et, tag))
> > +
> > +        return elem(SubElement(self.et, tag))
> >  
> >      def append(self, tag):
> >          retval = elem(SubElement(self.et, tag))
> > @@ -127,8 +127,8 @@ class etree(ebase):
> >          retval = self.et.find("./" + tag)
> >          if retval is not None:
> >              return elem(retval)
> > -        else:
> > -            return elem(SubElement(self.et.getroot(), tag))
> > +
> > +        return elem(SubElement(self.et.getroot(), tag))
> >  
> >      def set_child_position(self, child, pos):
> >          root = self.et.getroot()
> > -- 
> > 2.19.0.rc2
> > 
> 
> -- 
> Torben Hohn
> Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
> Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99
> 
> Hinweise zum Datenschutz finden Sie hier (Informations on data privacy 
> can be found here): https://linutronix.de/kontakt/Datenschutz.php
> 
> Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen | 
> Registergericht (Registration Court): Amtsgericht Freiburg i.Br., HRB700 
> 806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas Gleixner



-- 
Torben Hohn
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99

Hinweise zum Datenschutz finden Sie hier (Informations on data privacy 
can be found here): https://linutronix.de/kontakt/Datenschutz.php

Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen | 
Registergericht (Registration Court): Amtsgericht Freiburg i.Br., HRB700 
806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas Gleixner
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.linutronix.de/pipermail/elbe-devel/attachments/20180920/c84d8d02/attachment.sig>


More information about the elbe-devel mailing list