(object_name, module_name, block, func_ir, prefix=None, name=None)
return object_stmt
Imports specific object from a specific module. Do nothing if object is already imported in the block
Imports specific object from a specific module. Do nothing if object is already imported in the block
Imports specific object from a specific module . Do nothing if object is already imported in the block
def import_object(object_name, module_name, block, func_ir, prefix=None, name=None):
    """
    Imports specific object from a specific module. Do nothing if object is already imported in the block
    """

    def get_module_stmt(module_name, block, func_ir):
        module = modules[module_name]
        module_stmt = None

        for stmt in find_declarations(block, Global):
            rhs = stmt.value
            if rhs.value == module:
                module_stmt = stmt

        if module_stmt is None:
            stmt = declare_global(module_name, module, block, func_ir)
            module_stmt = stmt

        assert module_stmt is not None

        return module_stmt

    def find_object_stmt(object_name, block):
        object_stmt = None

        for stmt in find_operations(block, 'getattr'):
            expr = stmt.value
            if expr.attr == object_name:
                object_stmt = stmt

        return object_stmt

    object_stmt = find_object_stmt(object_name, block)

    if object_stmt is None:
        module_stmt = get_module_stmt(module_name, block, func_ir)
        object_stmt = make_getattr(object_name, module_stmt.target, block, func_ir, prefix=prefix, name=name)

    assert object_stmt is not None

    return object_stmt
def import_object ( object_name , module_name , block , func_ir , prefix = None , name = None ) : def get_module_stmt ( module_name , block , func_ir ) : module = modules [ module_name ] module_stmt = None for stmt in find_declarations ( block , Global ) : rhs = stmt . value if rhs . value == module : module_stmt = stmt if module_stmt is None : stmt = declare_global ( module_name , module , block , func_ir ) module_stmt = stmt assert module_stmt is not None return module_stmt def find_object_stmt ( object_name , block ) : object_stmt = None for stmt in find_operations ( block , 'getattr' ) : expr = stmt . value if expr . attr == object_name : object_stmt = stmt return object_stmt object_stmt = find_object_stmt ( object_name , block ) if object_stmt is None : module_stmt = get_module_stmt ( module_name , block , func_ir ) object_stmt = make_getattr ( object_name , module_stmt . target , block , func_ir , prefix = prefix , name = name ) assert object_stmt is not None return object_stmt