

def __new__(cls, *args):
    from sympy.functions.elementary.integers import ceiling
    if (len(args) == 1):
        if isinstance(args[0], (range if PY3 else xrange)):
            args = args[0].__reduce__()[1]
    slc = slice(*args)
    if (slc.step == 0):
        raise ValueError('step cannot be 0')
    (start, stop, step) = ((slc.start or 0), slc.stop, (slc.step or 1))
    try:
        (start, stop, step) = [(w if (w in [S.NegativeInfinity, S.Infinity]) else sympify(as_int(w))) for w in (start, stop, step)]
    except ValueError:
        raise ValueError(filldedent('\n    Finite arguments to Range must be integers; `imageset` can define\n    other cases, e.g. use `imageset(i, i/10, Range(3))` to give\n    [0, 1/10, 1/5].'))
    if (not step.is_Integer):
        raise ValueError(filldedent('\n    Ranges must have a literal integer step.'))
    if all((i.is_infinite for i in (start, stop))):
        if (start == stop):
            start = stop = S.One
        else:
            raise ValueError(filldedent('\n    Either the start or end value of the Range must be finite.'))
    if start.is_infinite:
        end = stop
    else:
        ref = (start if start.is_finite else stop)
        n = ceiling(((stop - ref) / step))
        if (n <= 0):
            start = end = 0
            step = 1
        else:
            end = (ref + (n * step))
    return Basic.__new__(cls, start, end, step)

dataset/ETHPy150Open sympy/sympy/sympy/sets/fancysets.py Range.__new__/original