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

Code before:
        self.update(left, bottom, right, top, wspace, hspace)

    def _repr_pretty_(self, p: Any, cycle: bool) -> None:
        del cycle
        name = self.__class__.__name__
        s = f"{name}(left={self.left}, bottom={self.bottom}, right={self.right}, "
        s += f" top={self.top}, wspace={self.wspace}, hspace={self.hspace})"
        p.text(s)

    def update(self, left=None, bottom=None, right=None, top=None,
               wspace=None, hspace=None):
        """
        Update the dimensions of the passed parameters. *None* means unchanged.
        """
        if ((left if left is not None else self.left)
                >= (right if right is not None else self.right)):
            raise ValueError('left cannot be >= right')
        if ((bottom if bottom is not None else self.bottom)
                >= (top if top is not None else self.top)):
            raise ValueError('bottom cannot be >= top')

        attributes = {'left': left, 'right': right, 'bottom': bottom, 'top': top,
                          'hspace': hspace, 'wspace': wspace}
        for key, value in attributes.items():
            if value is not None:
                setattr(self, key, value)

    def reset(self):
        """Restore the positioning parameters to the default values"""
        for key in self.get_subplot_params().keys():
            setattr(self, key, mpl.rcParams[f'figure.subplot.{key}'])

    def get_subplot_params(self) -> dict[str, float]:
        """
        Returns
        -------
        subplot_params : dictionary
            A dictionary with the subplot parameters
        """
        return self.__dict__.copy()


Review comment (suggestion):
This change is not needed, and I don't think it improves readability. The previous version was repetitive but very explicit what was going on.

Code after:
            as a fraction of the figure height.
        wspace : float, optional
            The width of the padding between subplots,
            as a fraction of the average Axes width.
        hspace : float, optional
            The height of the padding between subplots,
            as a fraction of the average Axes height.
        """
        for key in ["left", "bottom", "right", "top", "wspace", "hspace"]:
            setattr(self, key, mpl.rcParams[f"figure.subplot.{key}"])
        self.update(left, bottom, right, top, wspace, hspace)

    def update(self, left=None, bottom=None, right=None, top=None,
               wspace=None, hspace=None):
        """
        Update the dimensions of the passed parameters. *None* means unchanged.
        """
        if ((left if left is not None else self.left)
                >= (right if right is not None else self.right)):
            raise ValueError('left cannot be >= right')
        if ((bottom if bottom is not None else self.bottom)
                >= (top if top is not None else self.top)):
            raise ValueError('bottom cannot be >= top')
        if left is not None:
            self.left = left
        if right is not None:
            self.right = right
        if bottom is not None:
            self.bottom = bottom
        if top is not None:
            self.top = top
        if wspace is not None:
            self.wspace = wspace
        if hspace is not None:
            self.hspace = hspace

    def reset(self):
        """Restore the subplot positioning parameters to the default rcParams values"""
        for key in self.to_dict():
            setattr(self, key, mpl.rcParams[f'figure.subplot.{key}'])

    def to_dict(self):
        """Return a copy of the subplot parameters as a dict."""
        return self.__dict__.copy()