def get_import_nodes(node):
    return [
        x for c in node.children
        for x in c.children
        if c.type == syms.simple_stmt
        and is_import(x)
    ]
示例#2
0
def is_import_ish_stmt(node):
    # We also pretend gevent.monkey_patch() is an import because it's found
    # amongst them, and we don't want to create a LOGGER right after this.
    return (node.type == syms.simple_stmt and node.children
            and is_import(node.children[0])) or all(
                v in set(l.value for l in node.leaves())
                for v in {u'eventlet', u'monkey_patch', u'.'})
示例#3
0
def find_import_info(package, name, node):
    # type: (str, str, Node) -> Optional[ImportInfo]
    """
    Finds the import statement for <name> regardless of whether <name> is the binding name
        ex where name='a':
        import a => match AND import a as b => match BUT import b as a => None

    Parameters
    -----------
    package : str
    name : str
    node : Node

    Return
    -----------
    Optional[ImportInfo]
    """
    for child in node.children:
        if is_import(child):
            ret = get_import_info(child)
            imports = ret.imports.get(package)
            if imports is None:
                return None
            import_ = next((x for x in imports if x.entry == name), None)
            if import_:
                return ImportInfo(import_.entry, package, import_.binding_name)
        elif child.type == syms.simple_stmt:
            res = find_import_info(package, name, child)
            if res is None:
                continue
            else:
                return res
    return None
示例#4
0
def is_import_stmt(node):
    return (node.type == syms.simple_stmt and node.children
            and is_import(node.children[0]))
示例#5
0
def is_import_stmt(node):
    return (node.type == syms.simple_stmt and node.children and
            is_import(node.children[0]))
def get_import_nodes(node):
    return [
        x for c in node.children for x in c.children
        if c.type == syms.simple_stmt and is_import(x)
    ]