def get_imports(self, ast_body):
        """
        Return all the import statements given an AST body (AST nodes).

        Args:
            ast_body (compiled code's body): the body to filter.

        Returns:
            list of dict: the import statements.
        """
        imports = []
        for node in ast_body:
            if isinstance(node, ast.Import):
                imports.extend({'target': name.name, 'lineno': node.lineno}
                               for name in node.names)
            elif isinstance(node, ast.ImportFrom):
                for name in node.names:
                    name = (
                        self.absolute_name(self.depth - node.level) + '.'
                        if node.level > 0 else ''
                    ) + (
                        node.module + '.' if node.module else ''
                    ) + name.name
                    imports.append({'target': name, 'lineno': node.lineno})
            elif isinstance(node, Module.RECURSIVE_NODES):
                imports.extend(self.get_imports(node.body))
                if isinstance(node, ast.Try):
                    imports.extend(self.get_imports(node.finalbody))
        return imports
def get_imports ( self , ast_body ) : imports = [ ] for node in ast_body : if isinstance ( node , ast . Import ) : imports . extend ( { 'target' : name . name , 'lineno' : node . lineno } for name in node . names ) elif isinstance ( node , ast . ImportFrom ) : for name in node . names : name = ( self . absolute_name ( self . depth - node . level ) + '.' if node . level > 0 else '' ) + ( node . module + '.' if node . module else '' ) + name . name imports . append ( { 'target' : name , 'lineno' : node . lineno } ) elif isinstance ( node , Module . RECURSIVE_NODES ) : imports . extend ( self . get_imports ( node . body ) ) if isinstance ( node , ast . Try ) : imports . extend ( self . get_imports ( node . finalbody ) ) return imports
Return all the import statements given an AST body (AST nodes).

        Args:
            ast_body (compiled code's body): the body to filter.

        Returns:
            list of dict: the import statements.