Staging
v0.5.1
https://github.com/python/cpython
Raw File
Tip revision: 2e789a1f1d84b343a996e8654590703b5fbdd441 authored by Larry Hastings on 12 September 2015, 16:36:44 UTC
Final touch-ups for the What's New In Python 3.5 document.
Tip revision: 2e789a1
fix_repr.py
# Copyright 2006 Google, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.

"""Fixer that transforms `xyzzy` into repr(xyzzy)."""

# Local imports
from .. import fixer_base
from ..fixer_util import Call, Name, parenthesize


class FixRepr(fixer_base.BaseFix):

    BM_compatible = True
    PATTERN = """
              atom < '`' expr=any '`' >
              """

    def transform(self, node, results):
        expr = results["expr"].clone()

        if expr.type == self.syms.testlist1:
            expr = parenthesize(expr)
        return Call(Name("repr"), [expr], prefix=node.prefix)
back to top