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

Code before:
        color = mpl._val_or_rc(color, f"{name}.color")
        labelcolor = mpl._val_or_rc(labelcolor, f"{name}.labelcolor")
        if cbook._str_equal(labelcolor, 'inherit'):
            # inherit from tick color
            labelcolor = mpl.rcParams[f"{name}.color"]
        labelsize = mpl._val_or_rc(labelsize, f"{name}.labelsize")

        self._set_labelrotation(labelrotation)

        if zorder is None:
            if major:
                zorder = mlines.Line2D.zorder + 0.01
            else:
                zorder = mlines.Line2D.zorder
        self._zorder = zorder

        grid_color = (
            mpl._val_or_rc(
                grid_color, f"grid.{xaxis_yaxis}.{major_minor}.color"
            )
            if mpl.rcParams[f"grid.{xaxis_yaxis}.{major_minor}.color"] is not None
            else (
                mpl._val_or_rc(grid_color, f"grid.{major_minor}.color")
                if mpl.rcParams[f"grid.{major_minor}.color"] is not None
                else mpl._val_or_rc(grid_color, "grid.color")
            )
        )
        grid_linestyle = (
            mpl._val_or_rc(
                grid_linestyle, f"grid.{xaxis_yaxis}.{major_minor}.linestyle"
            )
            if mpl.rcParams[f"grid.{xaxis_yaxis}.{major_minor}.linestyle"] is not None
            else (
                mpl._val_or_rc(grid_linestyle, f"grid.{major_minor}.linestyle")
                if mpl.rcParams[f"grid.{major_minor}.linestyle"] is not None
                else mpl._val_or_rc(grid_linestyle, "grid.linestyle")
            )
        )
        grid_linewidth = (
            mpl._val_or_rc(
                grid_linewidth, f"grid.{xaxis_yaxis}.{major_minor}.linewidth"
            )
            if mpl.rcParams[f"grid.{xaxis_yaxis}.{major_minor}.linewidth"] is not None
            else (
                mpl._val_or_rc(grid_linewidth, f"grid.{major_minor}.linewidth")
                if mpl.rcParams[f"grid.{major_minor}.linewidth"] is not None
                else mpl._val_or_rc(grid_linewidth, "grid.linewidth")
            )
        )
        if grid_alpha is None and not mcolors._has_alpha_channel(grid_color):
            # alpha precedence: kwarg > color alpha > rcParams['grid.alpha']

Review comment (suggestion):
Optional: We have a number of these patterns. You could expand `_val_or_rc` to support a sequence of names (`_val_or_rc(val, *rc_names)`) and resolve to the first not-None, so that one could write this as:
```
grid_color = mpl._val_or_rc(
    grid_color,
    f"grid.{xaxis_yaxis}.{major_minor}.color",
    f"grid.{major_minor}.color"
)



Code after:
        labelcolor = mpl._val_or_rc(labelcolor, f"{name}.labelcolor")
        if cbook._str_equal(labelcolor, 'inherit'):
            # inherit from tick color
            labelcolor = mpl.rcParams[f"{name}.color"]
        labelsize = mpl._val_or_rc(labelsize, f"{name}.labelsize")

        self._set_labelrotation(labelrotation)

        if zorder is None:
            if major:
                zorder = mlines.Line2D.zorder + 0.01
            else:
                zorder = mlines.Line2D.zorder
        self._zorder = zorder

        grid_color = mpl._val_or_rc(
            grid_color,
            f"grid.{major_minor}.color",
            "grid.color",
        )
        grid_linestyle = mpl._val_or_rc(
            grid_linestyle,
            f"grid.{major_minor}.linestyle",
            "grid.linestyle",
        )
        grid_linewidth = mpl._val_or_rc(
            grid_linewidth,
            f"grid.{major_minor}.linewidth",
            "grid.linewidth",
        )
        if grid_alpha is None and not mcolors._has_alpha_channel(grid_color):
            # alpha precedence: kwarg > color alpha > rcParams['grid.alpha']
            # Note: only resolve to rcParams if the color does not have alpha
            # otherwise `grid(color=(1, 1, 1, 0.5))` would work like
            #   grid(color=(1, 1, 1, 0.5), alpha=rcParams['grid.alpha'])
            # so the that the rcParams default would override color alpha.
            grid_alpha = mpl._val_or_rc(
                # grid_alpha is None so we can use the first key
                mpl.rcParams[f"grid.{major_minor}.alpha"],
                "grid.alpha",
            )

        grid_kw = {k[5:]: v for k, v in kwargs.items() if k != "rotation_mode"}

        self.tick1line = mlines.Line2D(
            [], [],
            color=color, linestyle="none", zorder=zorder, visible=tick1On,
            markeredgecolor=color, markersize=self._size, markeredgewidth=self._width,
        )
        self.tick2line = mlines.Line2D(
            [], [],