~ubuntu-branches/ubuntu/maverick/python3.1/maverick

« back to all changes in this revision

Viewing changes to Lib/lib2to3/fixes/fix_zip.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-03-23 00:01:27 UTC
  • Revision ID: james.westby@ubuntu.com-20090323000127-5fstfxju4ufrhthq
Tags: upstream-3.1~a1+20090322
ImportĀ upstreamĀ versionĀ 3.1~a1+20090322

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
    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