# Buggy code
def get_selection_as_executable_code(self):
    """Return selected text as a processed text,
    to be executable in a Python/IPython interpreter"""
    ls = self.get_line_separator()

    _indent = lambda line: len(line) - len(line.lstrip())

    line_from, line_to = self.get_selection_bounds()
    text = self.get_selected_text()
    if not text:
        return

    lines = text.split(ls)
    if len(lines) > 1:
        # Multiline selection -> eventually fixing indentation
        original_indent = _indent(self.get_text_line(line_from))
        text = (" " * (original_indent - _indent(lines[0]))) + text

    # If there is a common indent to all lines, find it.
    # Moving from bottom line to top line ensures that blank
    # lines inherit the indent of the line *below* it,
    # which is the desired behavior.
    min_indent = 999
    current_indent = 0
    lines = text.split(ls)
    for i in range(len(lines) - 1, -1, -1):
        line = lines[i]
        if line.strip():
            current_indent = _indent(line)
            min_indent = min(current_indent, min_indent)
        else:
            lines[i] = " " * current_indent
    if min_indent:
        lines = [line[min_indent:] for line in lines]

    # Remove any leading whitespace or comment lines
    # since they confuse the reserved word detector that follows below
    lines_removed = 0
    while lines:
        first_line = lines[0].lstrip()
        if first_line == "" or first_line[0] == "#":
            lines_removed += 1
            lines.pop(0)
        else:
            break

    # Add an EOL character after the last line of code so that it gets
    # evaluated automatically by the console and any quote characters
    # are separated from the triple quotes of runcell
    lines.append(ls)

    # Add removed lines back to have correct traceback line numbers
    leading_lines_str = ls * lines_removed

    return leading_lines_str + ls.join(lines)


# Traceback (RuntimeError)
File "C:\Users\Chan Chak Tong\Anaconda3\lib\site-packages\spyder\plugins\editor\widgets\editor.py", line 2551, in run_cell
self._run_cell_text(text, block)
File "C:\Users\Chan Chak Tong\Anaconda3\lib\site-packages\spyder\plugins\editor\widgets\editor.py", line 2614, in _run_cell_text
cell_name = self._get_cell_name(block)
File "C:\Users\Chan Chak Tong\Anaconda3\lib\site-packages\spyder\plugins\editor\widgets\editor.py", line 2595, in _get_cell_name
raise RuntimeError('Not a cell?')
RuntimeError: Not a cell?
WARNING:spyder.widgets.github.backend:Failed to send bug report on Github. response={'code': 401, 'json': {'message': 'Bad credentials', 'documentation_url': 'https://developer.github.com/v3'}}

# Fixed code
def get_selection_as_executable_code(self, cursor=None):
    """Return selected text as a processed text,
    to be executable in a Python/IPython interpreter"""
    ls = self.get_line_separator()

    _indent = lambda line: len(line) - len(line.lstrip())

    line_from, line_to = self.get_selection_bounds(cursor)
    text = self.get_selected_text(cursor)
    if not text:
        return

    lines = text.split(ls)
    if len(lines) > 1:
        # Multiline selection -> eventually fixing indentation
        original_indent = _indent(self.get_text_line(line_from))
        text = (" " * (original_indent - _indent(lines[0]))) + text

    # If there is a common indent to all lines, find it.
    # Moving from bottom line to top line ensures that blank
    # lines inherit the indent of the line *below* it,
    # which is the desired behavior.
    min_indent = 999
    current_indent = 0
    lines = text.split(ls)
    for i in range(len(lines) - 1, -1, -1):
        line = lines[i]
        if line.strip():
            current_indent = _indent(line)
            min_indent = min(current_indent, min_indent)
        else:
            lines[i] = " " * current_indent
    if min_indent:
        lines = [line[min_indent:] for line in lines]

    # Remove any leading whitespace or comment lines
    # since they confuse the reserved word detector that follows below
    lines_removed = 0
    while lines:
        first_line = lines[0].lstrip()
        if first_line == "" or first_line[0] == "#":
            lines_removed += 1
            lines.pop(0)
        else:
            break

    # Add an EOL character after the last line of code so that it gets
    # evaluated automatically by the console and any quote characters
    # are separated from the triple quotes of runcell
    lines.append(ls)

    # Add removed lines back to have correct traceback line numbers
    leading_lines_str = ls * lines_removed

    return leading_lines_str + ls.join(lines)