Closed ewjoachim closed 3 years ago
(For a better understanding of the use case, my real life exemple looks like:
if n is None:
kwargs = {"end": self.file_size} if self.file_size is not None else {}
else:
kwargs = {"end": start + n}
read_range = ranges.Range(start=start, **kwargs)
If None was supported as "infinity", that would be:
read_range = ranges.Range(start=start, end=start + n if n is not None else self.file_size)
)
I agree with @ewjoachim, this would be helpful. I initially thought None could be used to imply infinity but that a decision hadn't been finalized and use INF to explicitly define infinity. Analogous to how SQL databases use null
for fields that have not been specified, but use ""
when it is explicitly meant to be blank.
Added a ranges.Inf
constant that represents a Range-compatible infinity. It should be negatable with -
like any other number, but should also work in a range with non-numeric types.
I have an optional
n
variable (integer or None), and I'd like it to be the end of my Range (meaning until n or open-ended if None)Is there a better choice for me than:
I guess having a special sentinel value for "infinity" (without resorting to using the private
_InfiniteValue
) would be nice. Also, None would make a pretty rational choice.