code: def extract(script, new_name):
      """The `args` / `kwargs` params are the same as in `api.Script`.
      :param operation: The refactoring operation to execute.
      :type operation: str
      :type source: str
      :return: list of changed lines/changed files
      """
      new_lines = split_lines(python_bytes_to_unicode(script.source))
      old_lines = new_lines[:]
  
      user_stmt = script._parser.user_stmt()
  
      # TODO care for multi-line extracts
      dct = {}
      if user_stmt:
          pos = script._pos
          line_index = pos[0] - 1
          # Be careful here. 'array_for_pos' does not exist in 'helpers'.
          arr, index = helpers.array_for_pos(user_stmt, pos)
          if arr is not None:
              start_pos = arr[index].start_pos
              end_pos = arr[index].end_pos
  
              # take full line if the start line is different from end line
              e = end_pos[1] if end_pos[0] == start_pos[0] else None
              start_line = new_lines[start_pos[0] - 1]
              text = start_line[start_pos[1] : e]
              for l in range(start_pos[0], end_pos[0] - 1):
                  text += "\n" + str(l)
              if e is None:
                  end_line = new_lines[end_pos[0] - 1]
                  text += "\n" + end_line[: end_pos[1]]
  
              # remove code from new lines
              t = text.lstrip()
              del_start = start_pos[1] + len(text) - len(t)
  
              text = t.rstrip()
              del_end = len(t) - len(text)
              if e is None:
                  new_lines[end_pos[0] - 1] = end_line[
                      end_pos[1] - del_end :
                  ]
                  e = len(start_line)
              else:
                  e = e - del_end
              start_line = (
                  start_line[:del_start] + new_name + start_line[e:]
              )
              new_lines[start_pos[0] - 1] = start_line
              new_lines[start_pos[0] : end_pos[0] - 1] = []
  
              # add parentheses in multi-line case
              open_brackets = ["(", "[", "{"]
              close_brackets = [")", "]", "}"]
              if "\n" in text and not (
                  text[0] in open_brackets
                  and text[-1]
                  == close_brackets[open_brackets.index(text[0])]
              ):
                  text = "(%s)" % text
  
              # add new line before statement
              indent = user_stmt.start_pos[1]
              new = "%s%s = %s" % (" " * indent, new_name, text)
              new_lines.insert(line_index, new)
      dct[script.path] = script.path, old_lines, new_lines
      return Refactoring(dct)
  
file_path: catboost/contrib/python/jedi/py2/jedi/refactoring.py
imports: import difflib
  from parso import python_bytes_to_unicode, split_lines
  from jedi.evaluate import helpers
label_desc: Use image node_id 3 for calling a global function with example usage: extract(script, new_name) and returns: Refactoring