fix_funcattrs.py 644 B

123456789101112131415161718192021
  1. """Fix function attribute names (f.func_x -> f.__x__)."""
  2. # Author: Collin Winter
  3. # Local imports
  4. from .. import fixer_base
  5. from ..fixer_util import Name
  6. class FixFuncattrs(fixer_base.BaseFix):
  7. BM_compatible = True
  8. PATTERN = """
  9. power< any+ trailer< '.' attr=('func_closure' | 'func_doc' | 'func_globals'
  10. | 'func_name' | 'func_defaults' | 'func_code'
  11. | 'func_dict') > any* >
  12. """
  13. def transform(self, node, results):
  14. attr = results["attr"][0]
  15. attr.replace(Name(("__%s__" % attr.value[5:]),
  16. prefix=attr.prefix))