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