1 | n/a | # Copyright 2008 Armin Ronacher. |
---|
2 | n/a | # Licensed to PSF under a Contributor Agreement. |
---|
3 | n/a | |
---|
4 | n/a | """Fixer for reduce(). |
---|
5 | n/a | |
---|
6 | n/a | Makes sure reduce() is imported from the functools module if reduce is |
---|
7 | n/a | used in that module. |
---|
8 | n/a | """ |
---|
9 | n/a | |
---|
10 | n/a | from lib2to3 import fixer_base |
---|
11 | n/a | from lib2to3.fixer_util import touch_import |
---|
12 | n/a | |
---|
13 | n/a | |
---|
14 | n/a | |
---|
15 | n/a | class FixReduce(fixer_base.BaseFix): |
---|
16 | n/a | |
---|
17 | n/a | BM_compatible = True |
---|
18 | n/a | order = "pre" |
---|
19 | n/a | |
---|
20 | n/a | PATTERN = """ |
---|
21 | n/a | power< 'reduce' |
---|
22 | n/a | trailer< '(' |
---|
23 | n/a | arglist< ( |
---|
24 | n/a | (not(argument<any '=' any>) any ',' |
---|
25 | n/a | not(argument<any '=' any>) any) | |
---|
26 | n/a | (not(argument<any '=' any>) any ',' |
---|
27 | n/a | not(argument<any '=' any>) any ',' |
---|
28 | n/a | not(argument<any '=' any>) any) |
---|
29 | n/a | ) > |
---|
30 | n/a | ')' > |
---|
31 | n/a | > |
---|
32 | n/a | """ |
---|
33 | n/a | |
---|
34 | n/a | def transform(self, node, results): |
---|
35 | n/a | touch_import('functools', 'reduce', node) |
---|