1 | n/a | """ |
---|
2 | n/a | Fixer that changes zip(seq0, seq1, ...) into list(zip(seq0, seq1, ...) |
---|
3 | n/a | unless there exists a 'from future_builtins import zip' statement in the |
---|
4 | n/a | top-level namespace. |
---|
5 | n/a | |
---|
6 | n/a | We avoid the transformation if the zip() call is directly contained in |
---|
7 | n/a | iter(<>), list(<>), tuple(<>), sorted(<>), ...join(<>), or for V in <>:. |
---|
8 | n/a | """ |
---|
9 | n/a | |
---|
10 | n/a | # Local imports |
---|
11 | n/a | from .. import fixer_base |
---|
12 | n/a | from ..fixer_util import Name, Call, in_special_context |
---|
13 | n/a | |
---|
14 | n/a | class FixZip(fixer_base.ConditionalFix): |
---|
15 | n/a | |
---|
16 | n/a | BM_compatible = True |
---|
17 | n/a | PATTERN = """ |
---|
18 | n/a | power< 'zip' args=trailer< '(' [any] ')' > |
---|
19 | n/a | > |
---|
20 | n/a | """ |
---|
21 | n/a | |
---|
22 | n/a | skip_on = "future_builtins.zip" |
---|
23 | n/a | |
---|
24 | n/a | def transform(self, node, results): |
---|
25 | n/a | if self.should_skip(node): |
---|
26 | n/a | return |
---|
27 | n/a | |
---|
28 | n/a | if in_special_context(node): |
---|
29 | n/a | return None |
---|
30 | n/a | |
---|
31 | n/a | new = node.clone() |
---|
32 | n/a | new.prefix = "" |
---|
33 | n/a | new = Call(Name("list"), [new]) |
---|
34 | n/a | new.prefix = node.prefix |
---|
35 | n/a | return new |
---|