/Lib/lib2to3/fixes/fix_reduce.py

http://unladen-swallow.googlecode.com/ · Python · 33 lines · 19 code · 7 blank · 7 comment · 0 complexity · 2fee5cc1f796c98a749dc789199da016 MD5 · raw file

  1. # Copyright 2008 Armin Ronacher.
  2. # Licensed to PSF under a Contributor Agreement.
  3. """Fixer for reduce().
  4. Makes sure reduce() is imported from the functools module if reduce is
  5. used in that module.
  6. """
  7. from .. import pytree
  8. from .. import fixer_base
  9. from ..fixer_util import Name, Attr, touch_import
  10. class FixReduce(fixer_base.BaseFix):
  11. PATTERN = """
  12. power< 'reduce'
  13. trailer< '('
  14. arglist< (
  15. (not(argument<any '=' any>) any ','
  16. not(argument<any '=' any>) any) |
  17. (not(argument<any '=' any>) any ','
  18. not(argument<any '=' any>) any ','
  19. not(argument<any '=' any>) any)
  20. ) >
  21. ')' >
  22. >
  23. """
  24. def transform(self, node, results):
  25. touch_import('functools', 'reduce', node)