]>
git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Python/Python-2.7.2/Lib/lib2to3/fixes/fix_filter.py
1 # Copyright 2007 Google, Inc. All Rights Reserved.
2 # Licensed to PSF under a Contributor Agreement.
4 """Fixer that changes filter(F, X) into list(filter(F, X)).
6 We avoid the transformation if the filter() call is directly contained
7 in iter(<>), list(<>), tuple(<>), sorted(<>), ...join(<>), or
10 NOTE: This is still not correct if the original code was depending on
11 filter(F, X) to return a string if X is a string and a tuple if X is a
12 tuple. That would require type inference, which we don't do. Let
13 Python 2.6 figure it out.
17 from ..pgen2
import token
18 from .. import fixer_base
19 from ..fixer_util
import Name
, Call
, ListComp
, in_special_context
21 class FixFilter(fixer_base
.ConditionalFix
):
31 (fp=NAME | vfpdef< '(' fp=NAME ')'> ) ':' xp=any
42 trailer< '(' arglist< none='None' ',' seq=any > ')' >
47 args=trailer< '(' [any] ')' >
51 skip_on
= "future_builtins.filter"
53 def transform(self
, node
, results
):
54 if self
.should_skip(node
):
57 if "filter_lambda" in results
:
58 new
= ListComp(results
.get("fp").clone(),
59 results
.get("fp").clone(),
60 results
.get("it").clone(),
61 results
.get("xp").clone())
63 elif "none" in results
:
64 new
= ListComp(Name(u
"_f"),
66 results
["seq"].clone(),
70 if in_special_context(node
):
74 new
= Call(Name(u
"list"), [new
])
75 new
.prefix
= node
.prefix