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

Code before:
    >>> from matplotlib.scale import ScaleBase
    >>> class CustomScale(ScaleBase):
    ...     @handle_axis_parameter
    ...     def __init__(self, axis, custom_param=1):
    ...         self.custom_param = custom_param
    """
    @wraps(init_func)
    def wrapper(self, *args, **kwargs):
        if args and isinstance(args[0], mpl.axis.Axis):
            return init_func(self, *args, **kwargs)
        else:
            # Remove 'axis' from kwargs to avoid double assignment
            kwargs.pop('axis', None)
            return init_func(self, None, *args, **kwargs)
    return wrapper


class LinearScale(ScaleBase):
    """
    The default linear scale.
    """

    name = 'linear'

    @handle_axis_parameter
    def __init__(self, axis=None):
        # This method is present only to prevent inheritance of the base class'
        # constructor docstring, which would otherwise end up interpolated into
        # the docstring of Axis.set_scale.
        """
        """  # noqa: D419

    def set_default_locators_and_formatters(self, axis):
        # docstring inherited
        axis.set_major_locator(AutoLocator())
        axis.set_major_formatter(ScalarFormatter())
        axis.set_minor_formatter(NullFormatter())
        # update the minor locator for x and y axis based on rcParams
        if (axis.axis_name == 'x' and mpl.rcParams['xtick.minor.visible'] or
                axis.axis_name == 'y' and mpl.rcParams['ytick.minor.visible']):
            axis.set_minor_locator(AutoMinorLocator())
        else:
            axis.set_minor_locator(NullLocator())

    def get_transform(self):
        """
        Return the transform for linear scaling, which is just the
        `~matplotlib.transforms.IdentityTransform`.
        """
        return IdentityTransform()


Review comment (suggestion):
Is there an advantage in making `axis` optional here? That should be handled be handled by the decorator. If there's no particular reason, then I'd prefer to keep the signature formally unchanged for now.

Code after:
    as the first argument.

    Examples
    --------
    >>> from matplotlib.scale import ScaleBase
    >>> class CustomScale(ScaleBase):
    ...     @_make_axis_parameter_optional
    ...     def __init__(self, axis, custom_param=1):
    ...         self.custom_param = custom_param
    """
    @wraps(init_func)
    def wrapper(self, *args, **kwargs):
        if args and isinstance(args[0], mpl.axis.Axis):
            return init_func(self, *args, **kwargs)
        else:
            # Remove 'axis' from kwargs to avoid double assignment
            axis = kwargs.pop('axis', None)
            return init_func(self, axis, *args, **kwargs)
    return wrapper


class LinearScale(ScaleBase):
    """
    The default linear scale.
    """

    name = 'linear'

    @_make_axis_parameter_optional
    def __init__(self, axis):
        # This method is present only to prevent inheritance of the base class'
        # constructor docstring, which would otherwise end up interpolated into
        # the docstring of Axis.set_scale.
        """
        """  # noqa: D419

    def set_default_locators_and_formatters(self, axis):
        # docstring inherited
        axis.set_major_locator(AutoLocator())
        axis.set_major_formatter(ScalarFormatter())
        axis.set_minor_formatter(NullFormatter())
        # update the minor locator for x and y axis based on rcParams
        if (axis.axis_name == 'x' and mpl.rcParams['xtick.minor.visible'] or
                axis.axis_name == 'y' and mpl.rcParams['ytick.minor.visible']):
            axis.set_minor_locator(AutoMinorLocator())
        else:
            axis.set_minor_locator(NullLocator())

    def get_transform(self):
        """
        Return the transform for linear scaling, which is just the