# Buggy code
def on_key_press(self, event):
    """Called whenever key pressed in canvas."""
    if event.native.isAutoRepeat():
        return
    else:
        if event.key == " ":
            if self._mode != Mode.PAN_ZOOM:
                self._mode_history = self.mode
                self._selected_data_history = copy(self.selected_data)
                self.mode = Mode.PAN_ZOOM
            else:
                self._mode_history = Mode.PAN_ZOOM
        elif event.key == "Shift":
            if self._mode == Mode.ADD:
                self.cursor = "forbidden"
        elif event.key == "p":
            self.mode = Mode.ADD
        elif event.key == "s":
            self.mode = Mode.SELECT
        elif event.key == "z":
            self.mode = Mode.PAN_ZOOM
        elif event.key == "c" and "Control" in event.modifiers:
            if self._mode == Mode.SELECT:
                self._copy_data()
        elif event.key == "v" and "Control" in event.modifiers:
            if self._mode == Mode.SELECT:
                self._paste_data()
        elif event.key == "a":
            if self._mode == Mode.SELECT:
                self.selected_data = self._indices_view[
                    list(range(len(self._data_view)))
                ]
                self._set_highlight()
        elif event.key == "Backspace":
            if self._mode == Mode.SELECT:
                self.remove_selected()


# Traceback (TypeError)
$ python examples/add_image.py
/home/jni/miniconda3/envs/cf/lib/python3.6/site-packages/vispy/visuals/markers.py:564: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
('a_edgewidth', np.float32, 1)])
/home/jni/miniconda3/envs/cf/lib/python3.6/site-packages/vispy/visuals/markers.py:564: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
('a_edgewidth', np.float32, 1)])
WARNING: Traceback (most recent call last):
File "examples/add_image.py", line 44, in <module>
layer.interpolation = 'nearest'
File "/home/jni/miniconda3/envs/cf/lib/python3.6/contextlib.py", line 88, in __exit__
next(self.gen)
File "/home/jni/projects/napari/napari/_qt/event_loop.py", line 31, in gui_qt
app.exec_()
File "/home/jni/miniconda3/envs/cf/lib/python3.6/site-packages/vispy/app/backends/_qt.py", line 501, in event
out = super(QtBaseCanvasBackend, self).event(ev)
File "/home/jni/miniconda3/envs/cf/lib/python3.6/site-packages/vispy/app/backends/_qt.py", line 495, in keyPressEvent
self._keyEvent(self._vispy_canvas.events.key_press, ev)
File "/home/jni/miniconda3/envs/cf/lib/python3.6/site-packages/vispy/app/backends/_qt.py", line 544, in _keyEvent
func(native=ev, key=key, text=text_type(ev.text()), modifiers=mod)
File "/home/jni/miniconda3/envs/cf/lib/python3.6/site-packages/vispy/util/event.py", line 455, in __call__
self._invoke_callback(cb, event)
File "/home/jni/miniconda3/envs/cf/lib/python3.6/site-packages/vispy/util/event.py", line 475, in _invoke_callback
self, cb_event=(cb, event))
<< caught exception here: >>
File "/home/jni/miniconda3/envs/cf/lib/python3.6/site-packages/vispy/util/event.py", line 471, in _invoke_callback
cb(event)
File "/home/jni/projects/napari/napari/_qt/qt_viewer.py", line 236, in on_key_press
layer.on_key_press(event)
File "/home/jni/projects/napari/napari/layers/points/points.py", line 968, in on_key_press
list(range(len(self._data_view)))
TypeError: list indices must be integers or slices, not list
ERROR: Invoking <bound method QtViewer.on_key_press of <napari._qt.qt_viewer.QtViewer object at 0x7fc1c12c1798>> for KeyEvent

# Fixed code
def on_key_press(self, event):
    """Called whenever key pressed in canvas."""
    if event.native.isAutoRepeat():
        return
    else:
        if event.key == " ":
            if self._mode != Mode.PAN_ZOOM:
                self._mode_history = self.mode
                self._selected_data_history = copy(self.selected_data)
                self.mode = Mode.PAN_ZOOM
            else:
                self._mode_history = Mode.PAN_ZOOM
        elif event.key == "Shift":
            if self._mode == Mode.ADD:
                self.cursor = "forbidden"
        elif event.key == "p":
            self.mode = Mode.ADD
        elif event.key == "s":
            self.mode = Mode.SELECT
        elif event.key == "z":
            self.mode = Mode.PAN_ZOOM
        elif event.key == "c" and "Control" in event.modifiers:
            if self._mode == Mode.SELECT:
                self._copy_data()
        elif event.key == "v" and "Control" in event.modifiers:
            if self._mode == Mode.SELECT:
                self._paste_data()
        elif event.key == "a":
            if self._mode == Mode.SELECT:
                self.selected_data = self._indices_view[: len(self._data_view)]
                self._set_highlight()
        elif event.key == "Backspace":
            if self._mode == Mode.SELECT:
                self.remove_selected()