int/long unification hides bugs

Jeff Epler jepler at unpythonic.net
Thu Oct 28 15:54:58 EDT 2004


On Thu, Oct 28, 2004 at 10:47:35AM -0700, Josiah Carlson wrote:
> class BoundedInt(object):
>     a = [0]
>     def f(a):
>         a[0] = 1
>         return 1
>     assert f(a)
>     if a[0]:
>         def __new__(cls, val, lower, upper):
>             #body for creating new bounded int object...
>             #only gets called if Python _is not run_ with -O option.
>     else:
>         def __new__(cls, val, lower, upper):
>             #optimized version is a plain integer
>             return val
>     del f;del a #clean out the namespace
>     #insert code for handling bounded integer arithmetic here

Is there a reason you didn't use 'if __debug__' here?

    class BoundedInt(object):
        ...
        if __debug__:
            def __new__ ...
        else:
            def __new__ ...

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20041028/b4deabe1/attachment.sig>


More information about the Python-list mailing list