# Buggy code
def __init__(self, title="napari", ndisplay=2, order=None, axis_labels=None):
    super().__init__()

    self.events = EmitterGroup(
        source=self,
        auto_connect=True,
        status=Event,
        help=Event,
        title=Event,
        interactive=Event,
        cursor=Event,
        reset_view=Event,
        active_layer=Event,
        palette=Event,
        grid=Event,
        layers_change=Event,
    )

    self.dims = Dims(ndim=None, ndisplay=ndisplay, order=order, axis_labels=axis_labels)

    self.layers = LayerList()

    self._status = "Ready"
    self._help = ""
    self._title = title
    self._cursor = "standard"
    self._cursor_size = None
    self._interactive = True
    self._active_layer = None
    self._grid_size = (1, 1)
    self.grid_stride = 1

    self._palette = None
    self.theme = "dark"

    self.dims.events.camera.connect(self.reset_view)
    self.dims.events.ndisplay.connect(self._update_layers)
    self.dims.events.order.connect(self._update_layers)
    self.dims.events.axis.connect(self._update_layers)
    self.layers.events.changed.connect(self._on_layers_change)
    self.layers.events.changed.connect(self._update_active_layer)
    self.layers.events.changed.connect(self._update_grid)

    self.keymap_providers = [self]

    # Hold callbacks for when mouse moves with nothing pressed
    self.mouse_move_callbacks = []
    # Hold callbacks for when mouse is pressed, dragged, and released
    self.mouse_drag_callbacks = []
    self._persisted_mouse_event = {}
    self._mouse_drag_gen = {}


# Traceback (IndexError)
Traceback (most recent call last):
File "/Users/cjw/Code/napari/napari/_qt/qt_viewer_buttons.py", line 148, in <lambda>
self.clicked.connect(lambda: self.viewer.layers.remove_selected())
File "/Users/cjw/Code/napari/napari/components/layerlist.py", line 139, in remove_selected
self.pop(i)
File "/Users/cjw/Code/napari/napari/utils/list/_model.py", line 64, in pop
self.events.removed(item=obj, index=key)
File "/Users/cjw/Code/napari/napari/utils/event.py", line 508, in __call__
self._invoke_callback(cb, event)
File "/Users/cjw/Code/napari/napari/utils/event.py", line 529, in _invoke_callback
cb_event=(cb, event),
File "/Users/cjw/Code/napari/napari/utils/event.py", line 523, in _invoke_callback
cb(event)
File "/Users/cjw/Code/napari/napari/utils/event.py", line 508, in __call__
self._invoke_callback(cb, event)
File "/Users/cjw/Code/napari/napari/utils/event.py", line 529, in _invoke_callback
cb_event=(cb, event),
File "/Users/cjw/Code/napari/napari/utils/event.py", line 523, in _invoke_callback
cb(event)
File "/Users/cjw/Code/napari/napari/components/viewer_model.py", line 513, in _update_grid
stride=self.grid_stride,
File "/Users/cjw/Code/napari/napari/components/viewer_model.py", line 500, in grid_view
self._subplot(layer, (i_row, i_column))
File "/Users/cjw/Code/napari/napari/components/viewer_model.py", line 528, in _subplot
scene_size, corner = self._scene_shape()
File "/Users/cjw/Code/napari/napari/components/viewer_model.py", line 266, in _scene_shape
size = [size[i] for i in self.dims.displayed]
File "/Users/cjw/Code/napari/napari/components/viewer_model.py", line 266, in <listcomp>
size = [size[i] for i in self.dims.displayed]
IndexError: index 4 is out of bounds for axis 0 with size 4

# Fixed code
def __init__(self, title="napari", ndisplay=2, order=None, axis_labels=None):
    super().__init__()

    self.events = EmitterGroup(
        source=self,
        auto_connect=True,
        status=Event,
        help=Event,
        title=Event,
        interactive=Event,
        cursor=Event,
        reset_view=Event,
        active_layer=Event,
        palette=Event,
        grid=Event,
        layers_change=Event,
    )

    self.dims = Dims(ndim=None, ndisplay=ndisplay, order=order, axis_labels=axis_labels)

    self.layers = LayerList()

    self._status = "Ready"
    self._help = ""
    self._title = title
    self._cursor = "standard"
    self._cursor_size = None
    self._interactive = True
    self._active_layer = None
    self._grid_size = (1, 1)
    self.grid_stride = 1

    self._palette = None
    self.theme = "dark"

    self.dims.events.camera.connect(self.reset_view)
    self.dims.events.ndisplay.connect(self._update_layers)
    self.dims.events.order.connect(self._update_layers)
    self.dims.events.axis.connect(self._update_layers)
    self.layers.events.changed.connect(self._update_active_layer)
    self.layers.events.changed.connect(self._update_grid)
    self.layers.events.changed.connect(self._on_layers_change)

    self.keymap_providers = [self]

    # Hold callbacks for when mouse moves with nothing pressed
    self.mouse_move_callbacks = []
    # Hold callbacks for when mouse is pressed, dragged, and released
    self.mouse_drag_callbacks = []
    self._persisted_mouse_event = {}
    self._mouse_drag_gen = {}