Re: How to avoid overflow errors

2007-09-15 Thread Steven D'Aprano
On Sat, 15 Sep 2007 02:45:10 -0700, James Stroud wrote: > Steven D'Aprano wrote: >> On Fri, 14 Sep 2007 18:19:45 -0700, James Stroud wrote: >> How do I subclass int and/or long so that my class also auto-converts only when needed? >>> Use __new__. >> >> The disadvantage of that is

Re: How to avoid overflow errors

2007-09-15 Thread Eduardo O. Padoan
On 9/15/07, Carl Banks <[EMAIL PROTECTED]> wrote: > On Fri, 14 Sep 2007 22:59:13 -0300, Eduardo O. Padoan wrote: > > > On 14 Sep 2007 18:08:00 -0700, Paul Rubin > > <"http://phr.cx"@nospam.invalid> wrote: > >> "Eduardo O. Padoan" <[EMAIL PROTECTED]> writes: > >> > Not totally unrelated, but in Py3k

Re: How to avoid overflow errors

2007-09-15 Thread James Stroud
Steven D'Aprano wrote: > On Fri, 14 Sep 2007 18:19:45 -0700, James Stroud wrote: > >>> How do I subclass int and/or long so that my class also auto-converts >>> only when needed? >>> >> Use __new__. > > The disadvantage of that is that your example code requires me to > duplicate my methods in t

Re: How to avoid overflow errors

2007-09-14 Thread Steven D'Aprano
On Fri, 14 Sep 2007 18:19:45 -0700, James Stroud wrote: >> How do I subclass int and/or long so that my class also auto-converts >> only when needed? >> >> >> >> > Use __new__. The disadvantage of that is that your example code requires me to duplicate my methods in the long version and the

Re: How to avoid overflow errors

2007-09-14 Thread Steven D'Aprano
On Fri, 14 Sep 2007 21:43:38 -0300, Eduardo O. Padoan wrote: >> How do I subclass int and/or long so that my class also auto-converts >> only when needed? > > What about just subclassing long - is this not an option? Of course it's an option. As it turned out, that was the easiest way for me to

Re: How to avoid overflow errors

2007-09-14 Thread Carl Banks
On Fri, 14 Sep 2007 22:59:13 -0300, Eduardo O. Padoan wrote: > On 14 Sep 2007 18:08:00 -0700, Paul Rubin > <"http://phr.cx"@nospam.invalid> wrote: >> "Eduardo O. Padoan" <[EMAIL PROTECTED]> writes: >> > Not totally unrelated, but in Py3k, as it seems, overflows are really >> > things of the past:

Re: How to avoid overflow errors

2007-09-14 Thread Eduardo O. Padoan
On 14 Sep 2007 18:08:00 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "Eduardo O. Padoan" <[EMAIL PROTECTED]> 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

Re: How to avoid overflow errors

2007-09-14 Thread James Stroud
Steven D'Aprano wrote: > I thought that overflow errors would be a thing of the past now that > Python automatically converts ints to longs as needed. Unfortunately, > that is not the case. > class MyInt(int): > ... pass > ... MyInt(sys.maxint) > 2147483647 MyInt(sys.maxint+1)

Re: How to avoid overflow errors

2007-09-14 Thread Paul Rubin
"Eduardo O. Padoan" <[EMAIL PROTECTED]> 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", "

Re: How to avoid overflow errors

2007-09-14 Thread Eduardo O. Padoan
On 9/14/07, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > I thought that overflow errors would be a thing of the past now that > Python automatically converts ints to longs as needed. Unfortunately, > that is not the case. > > >>> class MyInt(int): > ... pass > ... > >>> MyInt(sys.maxint) > 2147

How to avoid overflow errors

2007-09-14 Thread Steven D'Aprano
I thought that overflow errors would be a thing of the past now that Python automatically converts ints to longs as needed. Unfortunately, that is not the case. >>> class MyInt(int): ... pass ... >>> MyInt(sys.maxint) 2147483647 >>> MyInt(sys.maxint+1) Traceback (most recent call last): Fi