Issue 12666: map semantic change not documented in What's New (original) (raw)

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:20 admin set github: 56875
2011-12-03 14:01:20 jaraco set status: open -> closedresolution: fixed
2011-12-03 14:00:33 python-dev set nosy: + python-devmessages: +
2011-08-08 14:23:28 eric.araujo set messages: +
2011-08-06 16🔞30 jaraco set files: + cpython-issue12666-bc362109eed8.diffkeywords: + patchmessages: +
2011-08-06 14:53:25 eric.araujo set messages: +
2011-08-05 19:44:04 terry.reedy set versions: - Python 3.1
2011-08-05 19:00:18 rhettinger set assignee: docs@python -> rhettingernosy: + rhettinger
2011-08-05 16:39:03 jaraco set keywords: - patchmessages: +
2011-08-05 16:35:00 jaraco set messages: +
2011-08-05 16:33:45 jaraco set files: + bc362109eed8.diffkeywords: + patch
2011-08-05 16:30:10 eric.araujo set messages: +
2011-08-05 16:29:33 eric.araujo set hgrepos: + hgrepo51messages: + nosy: + eric.araujo
2011-08-01 22:04:02 jaraco set nosy: + benjamin.petersonmessages: + hgrepos: + hgrepo50
2011-07-31 16:02:29 jaraco set messages: +
2011-07-31 15:28:13 jaraco create