[elbe-devel] [PATCH v3] py3: fixup map vs. list issues

Torben Hohn torben.hohn at linutronix.de
Mon Dec 18 17:03:22 CET 2017


On Mon, Dec 18, 2017 at 03:41:19PM +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.
> 
> Signed-off-by: Manuel Traut <manut at linutronix.de>
> ---
>  elbepack/commands/pkgdiff.py | 4 ++--
>  elbepack/debianreleases.py   | 2 +-
>  elbepack/fstab.py            | 3 +--
>  3 files changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/elbepack/commands/pkgdiff.py b/elbepack/commands/pkgdiff.py
> index 7df30cb1..06abba13 100644
> --- a/elbepack/commands/pkgdiff.py
> +++ b/elbepack/commands/pkgdiff.py
> @@ -79,8 +79,8 @@ 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():
> -        if not p in gen_pkgs.keys():
> +    for p in fix_pkgs:
> +        if not p in gen_pkgs:
>              print("+<pkg>%s</pkg>" % p)

this hunk is good.

>  
>      for p in gen_pkgs.keys():
> 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())] )

this is an iteration over items() iterating with an iterator is not a
problem. Anyways, if you want to improve this line:

codename2suite = { v:k for k,v in suite2codename.items() }

this is dict comprehension, and is available since py2.7 
thats really sweet.

> diff --git a/elbepack/fstab.py b/elbepack/fstab.py
> index 47633002..05f8a7a0 100644
> --- a/elbepack/fstab.py
> +++ b/elbepack/fstab.py
> @@ -71,8 +71,7 @@ class mountpoint_dict (dict):
>              depth += 1
>  
>      def depthlist (self):
> -        mplist = self.keys()
> -        mplist.sort (key=mountpoint_dict.mountdepth)
> +        mplist = sorted (self.keys(), key=mountpoint_dict.mountdepth)

this hunk is good.

>  
>          return [self[x] for x in mplist]
>  
> -- 
> 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/20171218/12085ca9/attachment.sig>


More information about the elbe-devel mailing list