PageRenderTime 525ms CodeModel.GetById 413ms app.highlight 1ms RepoModel.GetById 109ms app.codeStats 0ms

/Lib/lib2to3/fixes/fix_reduce.py

http://unladen-swallow.googlecode.com/
Python | 33 lines | 20 code | 6 blank | 7 comment | 0 complexity | 2fee5cc1f796c98a749dc789199da016 MD5 | raw file
 1# Copyright 2008 Armin Ronacher.
 2# Licensed to PSF under a Contributor Agreement.
 3
 4"""Fixer for reduce().
 5
 6Makes sure reduce() is imported from the functools module if reduce is
 7used in that module.
 8"""
 9
10from .. import pytree
11from .. import fixer_base
12from ..fixer_util import Name, Attr, touch_import
13
14
15
16class FixReduce(fixer_base.BaseFix):
17
18    PATTERN = """
19    power< 'reduce'
20        trailer< '('
21            arglist< (
22                (not(argument<any '=' any>) any ','
23                 not(argument<any '=' any>) any) |
24                (not(argument<any '=' any>) any ','
25                 not(argument<any '=' any>) any ','
26                 not(argument<any '=' any>) any)
27            ) >
28        ')' >
29    >
30    """
31
32    def transform(self, node, results):
33        touch_import('functools', 'reduce', node)