<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># Copyright 2008 Armin Ronacher.
# Licensed to PSF under a Contributor Agreement.

"""Fixer for reduce().

Makes sure reduce() is imported from the functools module if reduce is
used in that module.
"""

from lib2to3 import fixer_base
from lib2to3.fixer_util import touch_import



class FixReduce(fixer_base.BaseFix):

    BM_compatible = True
    order = "pre"

    PATTERN = """
    power&lt; 'reduce'
        trailer&lt; '('
            arglist&lt; (
                (not(argument&lt;any '=' any&gt;) any ','
                 not(argument&lt;any '=' any&gt;) any) |
                (not(argument&lt;any '=' any&gt;) any ','
                 not(argument&lt;any '=' any&gt;) any ','
                 not(argument&lt;any '=' any&gt;) any)
            ) &gt;
        ')' &gt;
    &gt;
    """

    def transform(self, node, results):
        touch_import(u'functools', u'reduce', node)
</pre></body></html>