+++ /dev/null
-""" Fixer for itertools.(imap|ifilter|izip) --> (map|filter|zip) and\r
- itertools.ifilterfalse --> itertools.filterfalse (bugs 2360-2363)\r
-\r
- imports from itertools are fixed in fix_itertools_import.py\r
-\r
- If itertools is imported as something else (ie: import itertools as it;\r
- it.izip(spam, eggs)) method calls will not get fixed.\r
- """\r
-\r
-# Local imports\r
-from .. import fixer_base\r
-from ..fixer_util import Name\r
-\r
-class FixItertools(fixer_base.BaseFix):\r
- BM_compatible = True\r
- it_funcs = "('imap'|'ifilter'|'izip'|'izip_longest'|'ifilterfalse')"\r
- PATTERN = """\r
- power< it='itertools'\r
- trailer<\r
- dot='.' func=%(it_funcs)s > trailer< '(' [any] ')' > >\r
- |\r
- power< func=%(it_funcs)s trailer< '(' [any] ')' > >\r
- """ %(locals())\r
-\r
- # Needs to be run after fix_(map|zip|filter)\r
- run_order = 6\r
-\r
- def transform(self, node, results):\r
- prefix = None\r
- func = results['func'][0]\r
- if ('it' in results and\r
- func.value not in (u'ifilterfalse', u'izip_longest')):\r
- dot, it = (results['dot'], results['it'])\r
- # Remove the 'itertools'\r
- prefix = it.prefix\r
- it.remove()\r
- # Replace the node wich contains ('.', 'function') with the\r
- # function (to be consistant with the second part of the pattern)\r
- dot.remove()\r
- func.parent.replace(func)\r
-\r
- prefix = prefix or func.prefix\r
- func.replace(Name(func.value[1:], prefix=prefix))\r