def replace_none(idx, dim):
    """
    Normalize slices to canonical form, i.e.
    replace ``None`` with the appropriate integers.

    Parameters
    ----------
    idx: slice or other index
    dim: dimension length

    Examples
    --------
    >>> replace_none(slice(None, None, None), 10)
    slice(0, 10, 1)
    """
    if not isinstance(idx, slice):
        return idx

    start, stop, step = idx.start, idx.stop, idx.step

    if step is None:
        step = 1

    if step > 0:
        if start is None:
            start = 0

        if stop is None:
            stop = dim
    else:
        if start is None:
            start = dim - 1

        if stop is None:
            stop = -1

    return slice(start, stop, step)