[elbe-devel] [PATCH 17/40] pylint: rework redefinition of variable 'type'

Torben Hohn torben.hohn at linutronix.de
Thu Sep 20 12:01:56 CEST 2018


On Fri, Sep 14, 2018 at 01:56:29PM +0200, Manuel Traut wrote:
> avoid redefinition by not setting variables outside if/else statements
> 
> Signed-off-by: Manuel Traut <manut at linutronix.de>
> ---
>  elbepack/elbeproject.py   | 4 +++-
>  elbepack/xmlpreprocess.py | 5 +++--
>  2 files changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/elbepack/elbeproject.py b/elbepack/elbeproject.py
> index 0f29695a..1e2b0287 100644
> --- a/elbepack/elbeproject.py
> +++ b/elbepack/elbeproject.py
> @@ -422,9 +422,11 @@ class ElbeProject (object):
>          self.write_log_header()
>  
>          # Validate Apt Sources
> -        m = ValidationMode.CHECK_BINARIES
>          if build_sources:
>              m = ValidationMode.CHECK_ALL
> +        else:
> +            m = ValidationMode.CHECK_BINARIES
> +

this is an error, because ValidationMode.CHECK_ALL is a Bool, and
ValidationMode.CHECK_BINARIES is an int.

lets fix the root cause.

>          self.xml.validate_apt_sources(m, self.arch)
>  
>          if self.xml.has('target/pbuilder') and not skip_pbuild:
> diff --git a/elbepack/xmlpreprocess.py b/elbepack/xmlpreprocess.py
> index 39185ceb..e1456b4d 100644
> --- a/elbepack/xmlpreprocess.py
> +++ b/elbepack/xmlpreprocess.py
> @@ -27,8 +27,9 @@ def xmlpreprocess(fname, output, variants=None):
>  
>      # first convert variants to a set
>      if not variants:
> -        variants = []
> -    variants = set(variants)
> +        variants = set([])
> +    else:
> +        variants = set(variants)

this is a bit better.
but variants is a list, and then a set is assigned to it.
this probably only removes the pylint error, because it does not see
where the parameter comes from.

so... if we want to forbid assigning different types, we should use a
new variable named variant_set.

>  
>      schema_file = "https://www.linutronix.de/projects/Elbe/dbsfed.xsd"
>      parser = XMLParser(huge_tree=True)
> -- 
> 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
-------------- 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/7f2d9e77/attachment.sig>


More information about the elbe-devel mailing list