

def __getitem__(self, i):
    from sympy.functions.elementary.integers import ceiling
    ooslice = 'cannot slice from the end with an infinite value'
    zerostep = 'slice step cannot be zero'
    ambiguous = ('cannot unambiguously re-stride from the end ' + 'with an infinite value')
    if isinstance(i, slice):
        if self.size.is_finite:
            (start, stop, step) = i.indices(self.size)
            n = ceiling(((stop - start) / step))
            if (n <= 0):
                return Range(0)
            canonical_stop = (start + (n * step))
            end = (canonical_stop - step)
            ss = (step * self.step)
            return Range(self[start], (self[end] + ss), ss)
        else:
            start = i.start
            stop = i.stop
            if (i.step == 0):
                raise ValueError(zerostep)
            step = (i.step or 1)
            ss = (step * self.step)
            if self.stop.is_infinite:
                return self.reversed[(stop if (stop is None) else ((- stop) + 1)):(start if (start is None) else (- start)):step].reversed
            if (start is None):
                if (stop is None):
                    if (step < 0):
                        return Range(self[(- 1)], self.start, ss)
                    elif (step > 1):
                        raise ValueError(ambiguous)
                    else:
                        return self
                elif (stop < 0):
                    if (step < 0):
                        return Range(self[(- 1)], self[stop], ss)
                    else:
                        return Range(self.start, self[stop], ss)
                elif (stop == 0):
                    if (step > 0):
                        return Range(0)
                    else:
                        raise ValueError(ooslice)
                elif (stop == 1):
                    if (step > 0):
                        raise ValueError(ooslice)
                    else:
                        raise ValueError(ooslice)
                else:
                    raise ValueError(ooslice)
            elif (start < 0):
                if (stop is None):
                    if (step < 0):
                        return Range(self[start], self.start, ss)
                    else:
                        return Range(self[start], self.stop, ss)
                elif (stop < 0):
                    return Range(self[start], self[stop], ss)
                elif (stop == 0):
                    if (step < 0):
                        raise ValueError(ooslice)
                    else:
                        return Range(0)
                elif (stop > 0):
                    raise ValueError(ooslice)
            elif (start == 0):
                if (stop is None):
                    if (start < 0):
                        raise ValueError(ooslice)
                    elif (step > 1):
                        raise ValueError(ambiguous)
                    else:
                        return self
                elif (stop < 0):
                    if (step > 1):
                        raise ValueError(ambiguous)
                    elif (step == 1):
                        return Range(self.start, self[stop], ss)
                    else:
                        return Range(0)
                else:
                    raise ValueError(ooslice)
            elif (start > 0):
                raise ValueError(ooslice)
    else:
        if (not self):
            raise IndexError('Range index out of range')
        if (i == 0):
            return self.start
        if ((i == (- 1)) or (i is S.Infinity)):
            return (self.stop - self.step)
        rv = ((self.stop if (i < 0) else self.start) + (i * self.step))
        if rv.is_infinite:
            raise ValueError(ooslice)
        if ((rv < self.inf) or (rv > self.sup)):
            raise IndexError('Range index out of range')
        return rv

dataset/ETHPy150Open sympy/sympy/sympy/sets/fancysets.py Range.__getitem__/VarMisuse@645/787 `step`->`start`