@staticmethod
  def get_imports_from_bytecode(code_object, bytecode):
    """
      Parses the import statements from the bytecode and constructs a list of
      ``ImportDeclaration``.
    """
    last_import_ref_idx = BytecodeObject.get_last_import_ref(bytecode,
                                                             code_object)
    imports_bc = bytecode[:last_import_ref_idx + 1]

    import_stmts = []
    final_import_stmts = []

    # Split all the imports into single statements
    started = False
    buffer = []
    for tpl in imports_bc:
      if tpl[2] == LOAD_CONST and isinstance(tpl[3], int):
        started = True
        if len(buffer) > 0:
          import_stmts.append(buffer)
        buffer = []
      if started:
        buffer.append(tpl)
    if len(buffer) > 0:
      import_stmts.append(buffer)

    logger.debug("Found %d import statements", len(import_stmts))
    for import_stmt in import_stmts:
      arg = import_stmt[0][3]

      import_star = False
      import_root = None
      aliased_names = [] # [(import_name, import_alias)]
      num_dots = arg if arg >= 0 else 0 # We have -1 if it's not a relative import

      i, length = 0, len(import_stmt)
      while i < length:
        op, arg = import_stmt[i][2], import_stmt[i][3]
        next_op = import_stmt[i + 1][2] if i < length - 1 else -1
        next_next_op = import_stmt[i + 2][2] if i < length - 2 else -1

        if op in (IMPORT_NAME, IMPORT_FROM) and next_op in (STORE_NAME, STORE_FAST):
          # Simple import statement
            next_arg = import_stmt[i + 1][3]
            if next_arg == arg or arg.startswith(next_arg + '.'):
              # No alias
              aliased_names.append((arg, None))
            else:
              aliased_names.append((arg, next_arg))
        elif op == IMPORT_NAME and next_op == LOAD_ATTR and next_next_op == STORE_NAME:
          next_arg = import_stmt[i + 2][3]
          aliased_names.append((arg, next_arg))
        elif op == IMPORT_NAME:
          if import_root is not None:
            logger.error("Already defined a root: %s vs current %s", import_root, arg)
          if arg:
            import_root = arg

          if next_op == IMPORT_STAR:
            import_star = True
        i += 1

      # Instantiate the import stmt in the module
      imp_stmt = ImportDeclaration(code_object)
      imp_stmt.root = import_root
      imp_stmt.star = import_star
      imp_stmt.dots = num_dots
      imp_stmt.aliases = aliased_names
      final_import_stmts.append(imp_stmt)

    return final_import_stmts


  # Fine the last reference to an import stmt in the current code_object
dataset/ETHPy150Open neuroo/equip/equip/bytecode/code.py/BytecodeObject.get_imports_from_bytecode/original