How to avoid overflow errors

Eduardo O. Padoan eduardo.padoan at gmail.com
Fri Sep 14 21:59:13 EDT 2007


On 14 Sep 2007 18:08:00 -0700, Paul Rubin
<"http://phr.cx"@nospam.invalid> wrote:
> "Eduardo O. Padoan" <eduardo.padoan at gmail.com> writes:
> > Not totally unrelated, but in Py3k, as it seems, overflows are really
> > things of the past:
> >
> >
> > Python 3.0a1 (py3k:58061, Sep  9 2007, 13:18:37)
> > [GCC 4.1.3 20070831 (prerelease) (Ubuntu 4.1.2-16ubuntu1)] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> > >>> class MyInt(int):
> > ...     pass
> > ...
> > >>> import sys
> > >>> MyInt(sys.maxint)
> > 2147483647
> > >>> MyInt(sys.maxint+1)
> > 2147483648
>
> I'd be interested in knowing what happens in 3.0a1 with
>
>   a = itertools.count(sys.maxint)
>   print a.next()
>   print a.next()


>>> print(next(a))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: cannot count beyond PY_SSIZE_T_MAX

Hum, you've got me there. it is the same as in 2.x. Maybe the message
should be less crypt, at least - nothing that googling for
PY_SSIZE_T_MAX cant help.

-- 
http://www.advogato.org/person/eopadoan/
Bookmarks: http://del.icio.us/edcrypt



More information about the Python-list mailing list