[PATCH 5/9] Make map() usage Python 3 compatible (#1014220)
Anne Mulhern
amulhern at redhat.com
Wed Jan 28 22:47:32 UTC 2015
----- Original Message -----
> From: "Martin Kolman" <mkolman at redhat.com>
> To: anaconda-patches at lists.fedorahosted.org
> Sent: Wednesday, January 28, 2015 12:43:19 PM
> Subject: [PATCH 5/9] Make map() usage Python 3 compatible (#1014220)
>
> In Python 3 map() no longer returns a list, but an iterator.
> So replace map() with list comprehension or wrap it with list()
> where a list is expected. No changes are needed in code that either
> works fine with an iterator or just uses map() for the side effects.
>
> Signed-off-by: Martin Kolman <mkolman at redhat.com>
> ---
> pyanaconda/keyboard.py | 6 ++++--
> pyanaconda/rescue.py | 2 +-
> pyanaconda/ui/gui/spokes/filter.py | 4 ++--
> 3 files changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/pyanaconda/keyboard.py b/pyanaconda/keyboard.py
> index 1f3e572..e937f6e 100644
> --- a/pyanaconda/keyboard.py
> +++ b/pyanaconda/keyboard.py
> @@ -399,8 +399,10 @@ class LocaledWrapper(object):
> # if there are more variants than layouts, throw the trailing ones
> away
> variants = variants[:len(layouts)]
>
> - # map can be used with multiple lists and works like zipWith
> (Haskell)
> - return map(join_layout_variant, layouts, variants)
> + # map can be used with multiple lists and works like zipWith
> (Haskell),
> + # but we need to wrap it in list so that callers of this method
> still
> + # get a list in Python 3
> + return list(map(join_layout_variant, layouts, variants))
>
If you use the alternative,
return [join_layout_variant(layout, variant) for layout, variant in zip(layouts, variants)]
it will need zero lines of explanation (instead of three) and you can drop the lines above, which are:
> # if there are more variants than layouts, throw the trailing ones
> away
> variants = variants[:len(layouts)]
since zip will discard excess items from either list.
> @property
> def options(self):
> diff --git a/pyanaconda/rescue.py b/pyanaconda/rescue.py
> index 6702e2b..d52a8ff 100644
> --- a/pyanaconda/rescue.py
> +++ b/pyanaconda/rescue.py
> @@ -382,7 +382,7 @@ def doRescue(intf, rescue_mount, ksdata):
>
> # set a library path to use mounted fs
> libdirs = os.environ.get("LD_LIBRARY_PATH", "").split(":")
> - mounted = map(lambda dir: "/mnt/sysimage%s" % dir, libdirs)
> + mounted = ["/mnt/sysimage%s" % mdir for mdir in libdirs]
> os.environ["LD_LIBRARY_PATH"] = ":".join(libdirs + mounted)
>
> # find groff data dir
> diff --git a/pyanaconda/ui/gui/spokes/filter.py
> b/pyanaconda/ui/gui/spokes/filter.py
> index 1e2a3ac..3003b0f 100644
> --- a/pyanaconda/ui/gui/spokes/filter.py
> +++ b/pyanaconda/ui/gui/spokes/filter.py
> @@ -508,8 +508,8 @@ class FilterSpoke(NormalSpoke):
> self.disks = getDisks(self.storage.devicetree)
> self.selected_disks = self.data.ignoredisk.onlyuse[:]
>
> - self.ancestors = itertools.chain(*map(self._real_ancestors,
> self.disks))
> - self.ancestors = map(lambda d: d.name, self.ancestors)
> + self.ancestors = itertools.chain(*list(map(self._real_ancestors,
> self.disks)))
> + self.ancestors = [d.name for d in self.ancestors]
>
self.ancestors = [d.name for disk in self.disks for d in self._real_ancestors(disk)]
gets rid of all the faults of the previous construction and use of map as well.
> self._store.clear()
>
> --
> 2.1.0
>
> _______________________________________________
> anaconda-patches mailing list
> anaconda-patches at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
>
Some inline comments.
- mulhern
More information about the anaconda-patches
mailing list