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.

Unsupported provider

classification
Title: map semantic change not documented in What's New
Type: behavior Stage:
Components: 2to3 (2.x to 3.x conversion tool), Documentation Versions: Python 3.2, Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: benjamin.peterson, docs@python, eric.araujo, jaraco, python-dev, rhettinger
Priority: normal Keywords: easy, patch

Created on 2011-07-31 15:28 by jaraco, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bc362109eed8.diff jaraco, 2011-08-05 16:33 review
cpython-issue12666-bc362109eed8.diff jaraco, 2011-08-06 16:18
Repositories containing patches
https://bitbucket.org/jaraco/cpython-issue12666
http://bitbucket.org/jaraco/cpython-issue12666
Messages (11)
msg141470 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2011-07-31 15:28
In `whatsnew/3.0.html`, there is little said about the map builtin:

map() and filter() return iterators. If you really need a list, a quick fix is e.g. list(map(...)), but a better fix is often to use a list comprehension (especially when the original code uses lambda), or rewriting the code so it doesn’t need a list at all. Particularly tricky is map() invoked for the side effects of the function; the correct transformation is to use a regular for loop (since creating a list would just be wasteful).

This suggests that all one must do to port to Python 3 is wrap map in list, and in fact this is what the 2to3 fixers do, when in fact, map is semantically different in how it handles arguments of different lengths. Consider the following.

    def to_tuple(*args):
        return args

    print(list(map(to_tuple, [1,2,3], [4,5,6,7])))

On Python 2, this code outputs:

[(1, 4), (2, 5), (3, 6), (None, 7)]

On Python 3, this code outputs:

[(1, 4), (2, 5), (3, 6)]

I suggest three fixes (in order of importance):

1) Document the difference in whatsnew/3.0.html.
2) Describe how one should port code of this usage to 3.0.
3) Incorporate the porting in the 2to3 fixer (if possible).

If no one objects, I'll begin on (1). Does anyone have any suggestions for a clean approach to (2)?
msg141471 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2011-07-31 16:02
I believe the correct solution to (2) is to use itertools.zip_longest. So to port to Python 3, the example would use:

    print(list(map(to_tuple, itertools.zip_longest([1,2,3], [4,5,6,7]))))
msg141537 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2011-08-01 22:04
I've created a patch to address (1) and (2).

Is there any value in also including this in the 2to3 fixer? I can see that it's a simple translation, but adds complexity to the converted code. I'd be content to go with just a documentation patch. I'll defer to Benjamin or his delegate on whether or not to update 2to3.
msg141668 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-08-05 16:29
(HTTPS repos are not supported)
msg141669 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-08-05 16:30
Can you provide a public URI?
msg141670 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2011-08-05 16:35
I don't know how that repo got to be private; I created it just like every other public repo I have, and I thought I was only allowed one private repo (this was my second). In any case, I updated the setting, and now it appears to be accessible via the bug tracker.
msg141671 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2011-08-05 16:39
I'm not sure how the bugtracker patch mechanism works, but the patch it produced included a lot of changes that I didn't make (changesets already committed to the master repo).
msg141718 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-08-06 14:53
I have reported the bugs to the metatracker.  In the meantime, could you manually upload a diff?
msg141720 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2011-08-06 16:18
I'm attaching the diff at https://bitbucket.org/jaraco/cpython-issue12666/changeset/bc362109eed8
msg141778 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-08-08 14:23
The content of the patch is very helpful, but I question its location: I’m not sure people will find this nugget in the 3.2+ version of the What’s New in Python 3.0 document (sorry for not bringing that up sooner).  Maybe you could update Doc/library/functions.rst instead, and/or Doc/howto/pyporting.rst?
msg148802 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-12-03 14:00
New changeset 3b505df38fd8 by Jason R. Coombs in branch '3.2':
Issue #12666: Clarifying changes in map for Python 3
http://hg.python.org/cpython/rev/3b505df38fd8

New changeset 0e2812b16f5f by Jason R. Coombs in branch '3.2':
Issue #12666: Added section about map changes.
http://hg.python.org/cpython/rev/0e2812b16f5f

New changeset 51af35bd46f7 by Jason R. Coombs in branch 'default':
Merge fix for Issue #12666 from 3.2
http://hg.python.org/cpython/rev/51af35bd46f7
History
Date User Action Args
2022-04-11 14:57:20adminsetgithub: 56875
2011-12-03 14:01:20jaracosetstatus: open -> closed
resolution: fixed
2011-12-03 14:00:33python-devsetnosy: + python-dev
messages: + msg148802
2011-08-08 14:23:28eric.araujosetmessages: + msg141778
2011-08-06 16:18:30jaracosetfiles: + cpython-issue12666-bc362109eed8.diff
keywords: + patch
messages: + msg141720
2011-08-06 14:53:25eric.araujosetmessages: + msg141718
2011-08-05 19:44:04terry.reedysetversions: - Python 3.1
2011-08-05 19:00:18rhettingersetassignee: docs@python -> rhettinger

nosy: + rhettinger
2011-08-05 16:39:03jaracosetkeywords: - patch

messages: + msg141671
2011-08-05 16:35:00jaracosetmessages: + msg141670
2011-08-05 16:33:45jaracosetfiles: + bc362109eed8.diff
keywords: + patch
2011-08-05 16:30:10eric.araujosetmessages: + msg141669
2011-08-05 16:29:33eric.araujosethgrepos: + hgrepo51

messages: + msg141668
nosy: + eric.araujo
2011-08-01 22:04:02jaracosetnosy: + benjamin.peterson

messages: + msg141537
hgrepos: + hgrepo50
2011-07-31 16:02:29jaracosetmessages: + msg141471
2011-07-31 15:28:13jaracocreate