How to make an integer larger than any other integer?
<p>Note: while the accepted answer achieves the result I wanted, and @ecatmur answer provides a more comprehensive option, I feel it's very important to emphasize that my use case is a bad idea in the first place. This is explained very well in <a href="http://stackoverflow.com/a/39856605/336527">@Jason Orendorff answer below</a>.</p>

<p>Note: this question is not a duplicate of <a href="http://stackoverflow.com/questions/13795758/what-is-sys-maxint-in-python-3">the question about <code>sys.maxint</code></a>. It has nothing to do with <code>sys.maxint</code>; even in python 2 where <code>sys.maxint</code> is available, it does NOT represent largest integer (see the accepted answer).</p>

<p>I need to create an integer that's larger than any other integer, meaning an <code>int</code> object which returns <code>True</code> when compared to any other <code>int</code> object using <code>&gt;</code>. Use case: library function expects an integer, and the only easy way to force a certain behavior is to pass a very large integer.</p>

<p>In python 2, I can use <code>sys.maxint</code> (edit: I was wrong). In python 3, <code>math.inf</code> is the closest equivalent, but I can't convert it to <code>int</code>.</p>

<p>Konsta Vesterinen's <a href="https://github.com/kvesteri/infinity"><code>infinity.Infinity</code></a> would work (<a href="https://pypi.python.org/pypi/infinity/">pypi</a>), except that it doesn't inherit from <code>int</code>, but you can subclass it:</p>

<pre><code>from infinity import Infinity
class IntInfinity(Infinity, int):
    pass
assert isinstance(IntInfinity(), int)
assert IntInfinity() &gt; 1e100
</code></pre>

<p>Another package that implements "infinity" values is <a href="https://pypi.python.org/pypi/Extremes">Extremes</a>, which was salvaged from the rejected <a href="https://www.python.org/dev/peps/pep-0326/">PEP 326</a>; again, you'd need to subclass from <code>extremes.Max</code> and <code>int</code>.</p>

python python-3.x