PageRenderTime 212ms CodeModel.GetById 131ms app.highlight 2ms RepoModel.GetById 78ms app.codeStats 0ms

/Lib/lib2to3/fixes/fix_repr.py

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