class Base(object):

    def union(self, other):
        return Union(self, other)

def intersection(self, other):
    return Intersection(self, other)


class RangeSet(Base):

    def __init__(self, low, high):
        self.low = low
self.high = high

def __contains__(self, value):
    return value >= self.low and value < self.high


class Union(Base):

    def __init__(self, *sets):
        self.sets = sets

def __contains__(self, value):
    return any(value in x for x in self.sets)


class Intersection(Base):

    def __init__(self, *sets):
        self.sets = sets

def __contains__(self, value):
    return all(value in x for x in self.sets)
a = RangeSet(0, 10)
b = RangeSet(5, 15)
u = a.union(b)
i = a.intersection(b)
print(3 in u)
print(7 in u)
print(12 in u)
print(3 in i)
print(7 in i)
print(12 in i)
Есть ли код для подкласса, установленного в Python для больших xranges?