from typing import Optional


def _positivestop(stop: int, size: int, step: int) -> Optional[int]:
    """Convert a negative stop index to a non-negative integer.

    The index is interpreted relative to the position after the last item. If
    the index is smaller than ``-size``, the return value depends on ``step``.
    If ``step`` is positive, zero is returned. If ``step`` is negative, None is
    returned. Returning None for reverse slices ensures that an expression such
    as ``s[:-1000:-1]`` includes the first element of ``s``.
    """
    assert stop < 0  # noqa: S101

    stop += size
    if stop >= 0:
        return stop

    return 0 if step > 0 else None