About 20 people have pointed out that `inf` *IS* a constant. It's just in math rather then built-ins.

You can absolutely represent pi or e with a constant (3.14159265358979....)

The same cannot be said for infinity, hence why it should be a constant rather than a function call to retrieve the value

On Sat, Sep 5, 2020, 4:08 PM David Mertz <mertz@gnosis.cx> wrote:
On Sat, Sep 5, 2020 at 3:39 PM Cade Brown <brown.cade@gmail.com> wrote:
The fact that so many modules and packages must define an 'inf' is, to me, a signal that such a constant WOULD be useful. All of them (should) be referring to the same value, anyways, so why not make a global constant instead?

`pi` is a widely used constant that is defined in both numpy and math.  `e` is a widely used constant that is defined in both numpy and math.  Neither of them is included in builtins.  What is different about `inf` or `Infinity`?

The only real goal I've seen is that you hope that `x == eval(repr(x))` for floating point numbers.  But that is doomed to failure since it cannot work for NaN by its very definition.  So with your change the situation would be: It doesn't work for floats in general, but it works for two additional floating point values that it didn't used to work for.... and even that only means that you don't want to type one import:

>>> from math import inf
>>> inf == eval(repr(inf))
True

Lots of people have noted that being able to eval a repr is only a vague goal in Python, that works *often* at most.

---

Now if you want something genuinely useful, I wish we had an integer infinity.  There are places where `float('inf')` just isn't suitable because of the wrong type.

Doing a grep of CPython source, it looks like `sys.maxsize` occurs 343 times, and in almost every one of them it is a stand-in for "infinity."  I am certain there are other places where "a big number" is used because no integer infinity exists; sys.maxsize is only one spelling of that.

The general context where I'd want it is in code like this:

last = int.Infinity if not n:=smaller_last() else n
good_stuff = all_stuff[first:last+1]

Or in a similar spirit, we might be looking for a bound, and run `bound = min(new_thing, bound)` in a loop.  For that code, I need an initial value; albeit, in that case, float inf is probably fine.  And if I'm writing code to count the number of books on my shelf, sys.maxsize is a perfectly good starting point as well.  But int.Infinity expresses the actual intention more clearly.

--
The dead increasingly dominate and strangle both the living and the
not-yet born.  Vampiric capital and undead corporate persons abuse
the lives and control the thoughts of homo faber. Ideas, once born,
become abortifacients against new conceptions.