int/long unification hides bugs

Jeremy Fincher tweedgeezer at hotmail.com
Sat Oct 30 03:58:33 EDT 2004


Jeff Epler <jepler at unpythonic.net> wrote in message news:<mailman.5631.1098993377.5135.python-list at python.org>...
> 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?

__debug__ can be re-assigned.  It has no effect on asserts (anymore;
this formerly was not the case, and I much preferred it that way) but
reassignments to it are still visible to the program.

Jeremy-Finchers-Computer:~/src/my/python/supybot/plugins jfincher$
python -O
Python 2.3 (#1, Sep 13 2003, 00:49:11) 
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> __debug__
False
>>> __builtins__.__debug__ = True
>>> __debug__
True
>>>



More information about the Python-list mailing list