Repository: matplotlib/matplotlib
File: lib/matplotlib/offsetbox.py (Python)

Code before:
        height], or a list of [left, bottom] where the width and
        height will be assumed to be zero. The bbox will be
        transformed to display coordinate by the given transform.
        """
        if bbox is None or isinstance(bbox, BboxBase):
            self._bbox_to_anchor = bbox
        else:
            try:
                l = len(bbox)
            except TypeError as err:
                raise ValueError(f"Invalid bbox: {bbox}") from err

            if l == 2:
                bbox = [bbox[0], bbox[1], 0, 0]

            self._bbox_to_anchor = Bbox.from_bounds(*bbox)

        self._bbox_to_anchor_transform = transform
        self.stale = True

    @_compat_get_offset
    def get_offset(self, bbox, renderer):
        fontsize_in_pixels = renderer.points_to_pixels(self.prop.get_size_in_points())
        try:
            borderpad_x, borderpad_y = self.borderpad
        except (TypeError):
            borderpad_x = self.borderpad
            borderpad_y = self.borderpad
        pad_x_pixels = borderpad_x * fontsize_in_pixels
        pad_y_pixels = borderpad_y * fontsize_in_pixels
        bbox_to_anchor = self.get_bbox_to_anchor()
        x0, y0 = _get_anchored_bbox(
            self.loc,
            Bbox.from_bounds(0, 0, bbox.width, bbox.height),
            bbox_to_anchor,
            pad_x_pixels,
            pad_y_pixels
        )
        return x0 - bbox.x0, y0 - bbox.y0

    def update_frame(self, bbox, fontsize=None):
        self.patch.set_bounds(bbox.bounds)
        if fontsize:
            self.patch.set_mutation_scale(fontsize)

    def draw(self, renderer):
        # docstring inherited
        if not self.get_visible():
            return

        # update the location and size of the legend

Review comment (suggestion):
```suggestion
        except TypeError:
```
Brackets are not needed if we only catch one exception.

Code after:
        Set the bbox that the box is anchored to.

        *bbox* can be a Bbox instance, a list of [left, bottom, width,
        height], or a list of [left, bottom] where the width and
        height will be assumed to be zero. The bbox will be
        transformed to display coordinate by the given transform.
        """
        if bbox is None or isinstance(bbox, BboxBase):
            self._bbox_to_anchor = bbox
        else:
            try:
                l = len(bbox)
            except TypeError as err:
                raise ValueError(f"Invalid bbox: {bbox}") from err

            if l == 2:
                bbox = [bbox[0], bbox[1], 0, 0]

            self._bbox_to_anchor = Bbox.from_bounds(*bbox)

        self._bbox_to_anchor_transform = transform
        self.stale = True

    @_compat_get_offset
    def get_offset(self, bbox, renderer):
        # docstring inherited
        fontsize_in_pixels = renderer.points_to_pixels(self.prop.get_size_in_points())
        try:
            borderpad_x, borderpad_y = self.borderpad
        except TypeError:
            borderpad_x = self.borderpad
            borderpad_y = self.borderpad
        pad_x_pixels = borderpad_x * fontsize_in_pixels
        pad_y_pixels = borderpad_y * fontsize_in_pixels
        bbox_to_anchor = self.get_bbox_to_anchor()
        x0, y0 = _get_anchored_bbox(
            self.loc,
            Bbox.from_bounds(0, 0, bbox.width, bbox.height),
            bbox_to_anchor,
            pad_x_pixels,
            pad_y_pixels
        )
        return x0 - bbox.x0, y0 - bbox.y0

    def update_frame(self, bbox, fontsize=None):
        self.patch.set_bounds(bbox.bounds)
        if fontsize:
            self.patch.set_mutation_scale(fontsize)

    def draw(self, renderer):
        # docstring inherited