PageRenderTime 323ms CodeModel.GetById 161ms app.highlight 2ms RepoModel.GetById 159ms app.codeStats 0ms

/Lib/lib2to3/fixes/fix_zip.py

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