autoflake.py
def filter_from_import(line, unused_module):
    """Parse and filter ``from something import a, b, c``.

    Return line without unused import modules, or `pass` if all of the
    module in import is unused.
    """
    (indentation, imports) = re.split(pattern=r'\bimport\b',
                                      string=line, maxsplit=1)
    base_module = re.search(pattern=r'\bfrom\s+([^ ]+)',
                            string=indentation).group(1)

    # Create an imported module list with base module name
    # ex ``from a import b, c as d`` -> ``['a.b', 'a.c as d']``
    imports = re.split(pattern=r',', string=imports.strip())
    imports = [base_module + '.' + x.strip() for x in imports]

    # We compare full module name (``a.module`` not `module`) to
    # guarantee the exact same module as detected from pyflakes.
    filtered_imports = [x.replace(base_module + '.', '')
                        for x in imports if x not in unused_module]

    # All of the import in this statement is unused
    if not filtered_imports:
        return get_indentation(line) + 'pass' + get_line_ending(line)

    indentation += 'import '

    return (
        indentation +
        ', '.join(sorted(filtered_imports)) +
        get_line_ending(line))
def filter_from_import(line, unused_module):
    (indentation, imports) = re.split(pattern=r'\bimport\b',
                                      string=line, maxsplit=1)
    base_module = re.search(pattern=r'\bfrom\s+([^ ]+)',
                            string=indentation).group(1)

    # Create an imported module list with base module name
    # ex ``from a import b, c as d`` -> ``['a.b', 'a.c as d']``
    imports = re.split(pattern=r',', string=imports.strip())
    imports = [base_module + '.' + x.strip() for x in imports]

    # We compare full module name (``a.module`` not `module`) to
    # guarantee the exact same module as detected from pyflakes.
    filtered_imports = [x.replace(base_module + '.', '')
                        for x in imports if x not in unused_module]

    # All of the import in this statement is unused
    if not filtered_imports:
        return get_indentation(line) + 'pass' + get_line_ending(line)

    indentation += 'import '

    return (
        indentation +
        ', '.join(sorted(filtered_imports)) +
        get_line_ending(line))
def filter_from_import ( line , unused_module ) : ( indentation , imports ) = re . split ( pattern = r'\bimport\b' , string = line , maxsplit = 1 ) base_module = re . search ( pattern = r'\bfrom\s+([^ ]+)' , string = indentation ) . group ( 1 ) # Create an imported module list with base module name # ex ``from a import b, c as d`` -> ``['a.b', 'a.c as d']`` imports = re . split ( pattern = r',' , string = imports . strip ( ) ) imports = [ base_module + '.' + x . strip ( ) for x in imports ] # We compare full module name (``a.module`` not `module`) to # guarantee the exact same module as detected from pyflakes. filtered_imports = [ x . replace ( base_module + '.' , '' ) for x in imports if x not in unused_module ] # All of the import in this statement is unused if not filtered_imports : return get_indentation ( line ) + 'pass' + get_line_ending ( line ) indentation += 'import ' return ( indentation + ', ' . join ( sorted ( filtered_imports ) ) + get_line_ending ( line ) )
Parse and filter ``from something import a, b, c``.

    Return line without unused import modules, or `pass` if all of the
    module in import is unused.
Parse and filter from something import a b c .