[elbe-devel] [PATCH 14/25] py3: fixup map vs. list issues
Torben Hohn
torben.hohn at linutronix.de
Fri Dec 15 17:45:04 CET 2017
On Mon, Dec 11, 2017 at 10:11:08AM +0100, Manuel Traut wrote:
> map returns an iterator in py3 and a list in py2.
> If it is wrapped by list() it can be used the same way in py2 and py3.
the 2to3 tool is a bit dumb in this case.
there a not many cases, where we need this conversion.
and a for loop is certeinly not the case here.
>
> Signed-off-by: Manuel Traut <manut at linutronix.de>
> ---
> elbepack/commands/pkgdiff.py | 14 ++++++--------
> elbepack/debianize/base.py | 2 +-
> elbepack/debianreleases.py | 2 +-
> elbepack/fstab.py | 2 +-
> elbepack/templates.py | 2 +-
> elbepack/treeutils.py | 2 +-
> 6 files changed, 11 insertions(+), 13 deletions(-)
>
> diff --git a/elbepack/commands/pkgdiff.py b/elbepack/commands/pkgdiff.py
> index ec14f017..0cc27465 100644
> --- a/elbepack/commands/pkgdiff.py
> +++ b/elbepack/commands/pkgdiff.py
> @@ -77,16 +77,14 @@ def run_command( argv ):
> if p.current_ver and not p.essential:
> fix_pkgs[p.name] = p.current_ver
>
> - for p in fix_pkgs.keys():
this is ok ^^
but could be replaced with:
----------------------------------------------
for p in fix_pkgs:
----------------------------------------------
> - if not p in gen_pkgs.keys():
this is not ok ^^
however, this is equivalent, and looks better:
-----------------------------------------
if not p in gen_pkgs:
-----------------------------------------
> + for p in list(fix_pkgs.keys()):
> + if not p in list(gen_pkgs.keys()):
> print "+<pkg>%s</pkg>" % p
>
> - for p in gen_pkgs.keys():
> - if not p in fix_pkgs.keys():
> + for p in list(gen_pkgs.keys()):
> + if not p in list(fix_pkgs.keys()):
> print "-<pkg>%s</pkg>" % p
>
> - for p in fix_pkgs.keys():
> - if p in gen_pkgs.keys() and fix_pkgs[p] != gen_pkgs[p]:
> + for p in list(fix_pkgs.keys()):
> + if p in list(gen_pkgs.keys()) and fix_pkgs[p] != gen_pkgs[p]:
> print "%s: Version mismatch %s != %s" % (p, fix_pkgs[p], gen_pkgs[p])
> -
> -
> diff --git a/elbepack/debianize/base.py b/elbepack/debianize/base.py
> index 71948001..10a5558b 100644
> --- a/elbepack/debianize/base.py
> +++ b/elbepack/debianize/base.py
> @@ -40,7 +40,7 @@ class DebianizeBase (FormMultiPage):
>
> @classmethod
> def get_debianizer (cls):
> - for t in cls.srctypes.values ():
> + for t in list(cls.srctypes.values ()):
not necessary.
> match = True
> for f in t.files:
> if not os.path.exists (f):
> diff --git a/elbepack/debianreleases.py b/elbepack/debianreleases.py
> index ee2d793f..96e653ca 100644
> --- a/elbepack/debianreleases.py
> +++ b/elbepack/debianreleases.py
> @@ -32,4 +32,4 @@ suite2codename = { 'oldoldoldstable': 'squeeze',
>
>
> # generate reverse mapping
> -codename2suite = dict( [(v,k) for k,v in suite2codename.items()] )
> +codename2suite = dict( [(v,k) for k,v in list(suite2codename.items())] )
> diff --git a/elbepack/fstab.py b/elbepack/fstab.py
> index 47633002..5ea56077 100644
> --- a/elbepack/fstab.py
> +++ b/elbepack/fstab.py
> @@ -71,7 +71,7 @@ class mountpoint_dict (dict):
> depth += 1
>
> def depthlist (self):
> - mplist = self.keys()
> + mplist = list(self.keys())
> mplist.sort (key=mountpoint_dict.mountdepth)
lets take this one here:
------------------------------------------------------------------
mplist = sorted (self.keys(), key=mountpoint_dict.mountdepth)
------------------------------------------------------------------
>
> return [self[x] for x in mplist]
> diff --git a/elbepack/templates.py b/elbepack/templates.py
> index 634b7ccd..9bbca711 100644
> --- a/elbepack/templates.py
> +++ b/elbepack/templates.py
> @@ -92,7 +92,7 @@ def get_initvm_preseed( xml ):
>
> def preseed_to_text( pres ):
> retval = ""
> - for k,v in pres.items():
> + for k,v in list(pres.items()):
not necessary.
> retval += "%s\t%s\t%s\t%s\n" % (k[0], k[1], v[0], v[1])
>
> return retval
> diff --git a/elbepack/treeutils.py b/elbepack/treeutils.py
> index bcbd415e..8efc401c 100644
> --- a/elbepack/treeutils.py
> +++ b/elbepack/treeutils.py
> @@ -71,7 +71,7 @@ class ebase(object):
> return None
>
> def all( self, path ):
> - return map(elem, self.et.findall(path))
> + return list(map(elem, self.et.findall(path)))
this function seems to be used in a single place.
----------------------------------------------------------------
elbepack/xsdtoasciidoc.mako:% for n in xml.all('./'):
----------------------------------------------------------------
at this place, its ok, when we return an iterator.
so this hunk is not necessary.
>
> def __iter__( self ):
> return eiter(iter(self.et))
> --
> 2.15.1
>
>
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel
--
Mit freundlichen Grüßen
Torben Hohn
Linutronix GmbH
Standort: Bremen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99
Firmensitz / Registered Office: D-88690 Uhldingen, Bahnhofstr. 3
Registergericht / Local District Court: Amtsgericht Freiburg i. Br.; HRB
Nr. / Trade register no.: 700 806
Geschäftsführer / Managing Directors: Heinz Egger, Thomas Gleixner
Eine Bitte von uns: Sollten Sie diese E-Mail irrtümlich erhalten haben,
benachrichtigen Sie uns in diesem Falle bitte sobald wie es Ihnen
möglich ist, durch Antwort-Mail. Vielen Dank!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.linutronix.de/pipermail/elbe-devel/attachments/20171215/2470ad5b/attachment.sig>
More information about the elbe-devel
mailing list