Now that Python is beginning to embrace type annotations, is it worth revisiting the idea of having extended integers and an integer infinity?
I found myself trying to annotate this line:
events_to_do: Union[int, float] = math.inf
where I am only including float in the union to accommodate math.inf.
I'm interested in exploring this concrete proposal:
Add a class to the numeric hierarchy (https://www.python.org/dev/peps/pep-3141/) ExtendedIntegral whereby Real :> ExtendedIntegral :> Integral. Add a sentinel math.int_inf that obeys all of the same kinds of rules as math.inf does.
Then, I could annotate more simply:
events_to_do: ExtendedIntegral = math.int_inf
With respect to Python, this is discussed somewhat here https://stackoverflow.com/questions/24587994/infinite-integer-in-python/3572....
The name "extended integer" is discussed somewhat here https://math.stackexchange.com/questions/1442961/extended-integers. A quick search of papers shows that it is sometimes used in this sense: https://scholar.google.com/scholar?q=%22extended+integer
An intuitive way to annotate that variable in Python 3.8 would be:
events_to_do: Union[int, Literal[math.inf]] = math.inf
That has the advantage of matching the way you would write it now, without changing the core language.
It unfortunately doesn't work, because PEP 586 provisionally disallows float literals, but it may become supported in the future.
One other possible advantage of doing it this way is that you don't have to include negative infinity (-math.inf). There are applications where you only need positive infinity, or only need negative infinity.