fix_repr.py 613 B

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