[issue28837] 2to3 does not wrap zip correctly

Stuart Berg report at bugs.python.org
Thu Jan 19 10:08:08 EST 2017


Stuart Berg added the comment:

In addition to zip(), this problem also affects map() and filter().

The problem is that the match patterns in FixZip, FixMap, and FixFilter do not allow for more than one "trailer" node.  (And even if they did, their transform() methods aren't expecting it.)

For example, in the following expression, 'zip' is followed by two 'trailers', which are '(a,b)', and [0]:

zip(a,b)[0]

... but FixZip.PATTERN only expects a single trailer (the argument list), so the presence of a second trailer prevents the match: https://git.io/vMDP9


(Here's the relevant line of the grammar: https://git.io/vMDPJ)

I've written a patch that fixes this problem for zip, map, and filter, with tests.  See attached.

BTW, this problem was previously reported in 21628, but that issue was incorrectly closed as a duplicate, so I'm submitting my patch here.

----------
keywords: +patch
nosy: +stuarteberg
Added file: http://bugs.python.org/file46339/fix-28837.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28837>
_______________________________________


More information about the Python-bugs-list mailing list