def __len__(self):
        """Get length of this integer set. In case the length is larger than
        2**31 (including infinitely sized integer sets), it raises an
        OverflowError. This is due to len() restricting the size to
        0 <= len < 2**31."""

        if not self._ranges:
            return 0
        if self._ranges[0][0] is _MININF or self._ranges[-1][1] is _MAXINF:
            raise OverflowError("Infinitely sized integer set.")
        rlen = 0
        for r in self._ranges:
            rlen += r[1]-r[0]
        if rlen >= 2**31:
            raise OverflowError("Integer set bigger than 2**31.")
        return rlen
Get length of this integer set. In case the length is larger than
        2**31 (including infinitely sized integer sets), it raises an
        OverflowError. This is due to len() restricting the size to
        0 <= len < 2**31.
recipes/Python/466286_Integer_set_type/recipe-466286.py