1 | n/a | # Copyright 2006 Google, Inc. All Rights Reserved. |
---|
2 | n/a | # Licensed to PSF under a Contributor Agreement. |
---|
3 | n/a | |
---|
4 | n/a | """Fixer that transforms `xyzzy` into repr(xyzzy).""" |
---|
5 | n/a | |
---|
6 | n/a | # Local imports |
---|
7 | n/a | from .. import fixer_base |
---|
8 | n/a | from ..fixer_util import Call, Name, parenthesize |
---|
9 | n/a | |
---|
10 | n/a | |
---|
11 | n/a | class FixRepr(fixer_base.BaseFix): |
---|
12 | n/a | |
---|
13 | n/a | BM_compatible = True |
---|
14 | n/a | PATTERN = """ |
---|
15 | n/a | atom < '`' expr=any '`' > |
---|
16 | n/a | """ |
---|
17 | n/a | |
---|
18 | n/a | def transform(self, node, results): |
---|
19 | n/a | expr = results["expr"].clone() |
---|
20 | n/a | |
---|
21 | n/a | if expr.type == self.syms.testlist1: |
---|
22 | n/a | expr = parenthesize(expr) |
---|
23 | n/a | return Call(Name("repr"), [expr], prefix=node.prefix) |
---|