/opt/alt/python310/lib64/python3.10/lib2to3/fixes
""" Fixer for imports of itertools.(imap|ifilter|izip|ifilterfalse) """ # Local imports from lib2to3 import fixer_base from lib2to3.fixer_util import BlankLine, syms, token class FixItertoolsImports(fixer_base.BaseFix): BM_compatible = True PATTERN = """ import_from< 'from' 'itertools' 'import' imports=any > """ %(locals()) def transform(self, node, results): imports = results['imports'] if imports.type == syms.import_as_name or not imports.children: children = [imports] else: children = imports.children for child in children[::2]: if child.type == token.NAME: member = child.value name_node = child elif child.type == token.STAR: # Just leave the import as is. return else: assert child.type == syms.import_as_name name_node = child.children[0] member_name = name_node.value if member_name in ('imap', 'izip', 'ifilter'): child.value = None child.remove() elif member_name in ('ifilterfalse', 'izip_longest'): node.changed() name_node.value = ('filterfalse' if member_name[1] == 'f' else 'zip_longest') # Make sure the import statement is still sane children = imports.children[:] or [imports] remove_comma = True for child in children: if remove_comma and child.type == token.COMMA: child.remove() else: remove_comma ^= True while children and children[-1].type == token.COMMA: children.pop().remove() # If there are no imports left, just get rid of the entire statement if (not (imports.children or getattr(imports, 'value', None)) or imports.parent is None): p = node.prefix node = BlankLine() node.prefix = p return node
.
Edit
..
Edit
__init__.py
Edit
__pycache__
Edit
fix_apply.py
Edit
fix_asserts.py
Edit
fix_basestring.py
Edit
fix_buffer.py
Edit
fix_dict.py
Edit
fix_except.py
Edit
fix_exec.py
Edit
fix_execfile.py
Edit
fix_exitfunc.py
Edit
fix_filter.py
Edit
fix_funcattrs.py
Edit
fix_future.py
Edit
fix_getcwdu.py
Edit
fix_has_key.py
Edit
fix_idioms.py
Edit
fix_import.py
Edit
fix_imports.py
Edit
fix_imports2.py
Edit
fix_input.py
Edit
fix_intern.py
Edit
fix_isinstance.py
Edit
fix_itertools.py
Edit
fix_itertools_imports.py
Edit
fix_long.py
Edit
fix_map.py
Edit
fix_metaclass.py
Edit
fix_methodattrs.py
Edit
fix_ne.py
Edit
fix_next.py
Edit
fix_nonzero.py
Edit
fix_numliterals.py
Edit
fix_operator.py
Edit
fix_paren.py
Edit
fix_print.py
Edit
fix_raise.py
Edit
fix_raw_input.py
Edit
fix_reduce.py
Edit
fix_reload.py
Edit
fix_renames.py
Edit
fix_repr.py
Edit
fix_set_literal.py
Edit
fix_standarderror.py
Edit
fix_sys_exc.py
Edit
fix_throw.py
Edit
fix_tuple_params.py
Edit
fix_types.py
Edit
fix_unicode.py
Edit
fix_urllib.py
Edit
fix_ws_comma.py
Edit
fix_xrange.py
Edit
fix_xreadlines.py
Edit
fix_zip.py
Edit