This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: fixer for map(None, ...) needs to consider multi-argument case
Type: behavior Stage: needs patch
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.1, Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, georg.brandl, segfaulthunter
Priority: high Keywords:

Created on 2009-10-25 17:53 by georg.brandl, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (8)
msg94455 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-10-25 17:53
Currently, ``map(None, a)`` is recognized and converted to ``list(a)``
which is correct but quite useless.

``map(None, a, b, ...)`` is not treated specially.  An approximate
translation would be ``map(lambda *xs: xs, a, b, ...)`` which however
doesn't take into account that the new map cuts after the shortest
sequence instead of "filling up" the shorter ones with Nones.

That should probably produce a warning.
msg94456 - (view) Author: Florian Mayer (segfaulthunter) Date: 2009-10-25 18:23
A full fix would be

list(map(fun, *zip(*itertools.zip_longest(a, b, ...))))

and if fun is None

list(map(lambda *xs: xs, *zip(*itertools.zip_longest(a, b, ...))))
msg94513 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-10-26 21:30
Fixed in r75734.
msg94576 - (view) Author: Florian Mayer (segfaulthunter) Date: 2009-10-27 19:52
I dare to disagree on this being an adequate fix. Request to reopen.
msg94577 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-10-27 20:22
2009/10/27 Florian Mayer <report@bugs.python.org>:
>
> Florian Mayer <flormayer@aim.com> added the comment:
>
> I dare to disagree on this being an adequate fix. Request to reopen.

What would you prefer?
msg94579 - (view) Author: Florian Mayer (segfaulthunter) Date: 2009-10-27 20:43
At least converting

map(None, a, b, ...)

to

map(lambda *xs: xs, a, b, ...)

I can understand if you prefer not to add the itertools.zip_longest
workaround, although that would be the correct translation, of course.
msg94580 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-10-27 20:57
2009/10/27 Florian Mayer <report@bugs.python.org>:
>
> Florian Mayer <flormayer@aim.com> added the comment:
>
> At least converting
>
> map(None, a, b, ...)
>
> to
>
> map(lambda *xs: xs, a, b, ...)

Well, since that's not always correct, we should not translate to it.
msg94581 - (view) Author: Florian Mayer (segfaulthunter) Date: 2009-10-27 20:58
When could this possibly be wrong, if I may ask?
History
Date User Action Args
2022-04-11 14:56:54adminsetgithub: 51452
2009-10-27 20:58:37segfaulthuntersetmessages: + msg94581
2009-10-27 20:57:51benjamin.petersonsetmessages: + msg94580
2009-10-27 20:43:35segfaulthuntersetmessages: + msg94579
2009-10-27 20:22:46benjamin.petersonsetmessages: + msg94577
2009-10-27 19:52:53segfaulthuntersetmessages: + msg94576
2009-10-26 21:30:10benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg94513

resolution: fixed
2009-10-25 18:23:09segfaulthuntersetmessages: + msg94456
2009-10-25 18:19:01segfaulthuntersetnosy: + segfaulthunter
2009-10-25 17:53:24georg.brandlcreate