1 | n/a | """Fixer that changes input(...) into eval(input(...)).""" |
---|
2 | n/a | # Author: Andre Roberge |
---|
3 | n/a | |
---|
4 | n/a | # Local imports |
---|
5 | n/a | from .. import fixer_base |
---|
6 | n/a | from ..fixer_util import Call, Name |
---|
7 | n/a | from .. import patcomp |
---|
8 | n/a | |
---|
9 | n/a | |
---|
10 | n/a | context = patcomp.compile_pattern("power< 'eval' trailer< '(' any ')' > >") |
---|
11 | n/a | |
---|
12 | n/a | |
---|
13 | n/a | class FixInput(fixer_base.BaseFix): |
---|
14 | n/a | BM_compatible = True |
---|
15 | n/a | PATTERN = """ |
---|
16 | n/a | power< 'input' args=trailer< '(' [any] ')' > > |
---|
17 | n/a | """ |
---|
18 | n/a | |
---|
19 | n/a | def transform(self, node, results): |
---|
20 | n/a | # If we're already wrapped in an eval() call, we're done. |
---|
21 | n/a | if context.match(node.parent.parent): |
---|
22 | n/a | return |
---|
23 | n/a | |
---|
24 | n/a | new = node.clone() |
---|
25 | n/a | new.prefix = "" |
---|
26 | n/a | return Call(Name("eval"), [new], prefix=node.prefix) |
---|