The problem with that though is:  I am not the one calling reload(). That is actually being called for me by web.py (or django, or some other framework, take your pick).  More than that, I believe it's called (or caused, anyway) by something happening in WSGI under apache.  (And I don't really want to start digging around in there either)<div>
<br></div><div>The patch in this case is very limited in scope, and all it inflicts on the subject code inside of decimal.Decimal.__new__(), is better programming practices.</div><div><br></div><div>--jeff<br><div><br><div class="gmail_quote">
On Fri, Mar 2, 2012 at 5:49 PM, Ethan Furman <span dir="ltr"><<a href="mailto:ethan@stoneleaf.us">ethan@stoneleaf.us</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Jeff Beardsley wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
HISTORY:  <br>
In using python 2.7.2 for awhile on a web project (apache/wsgi web.py), I discovered a problem in using decimal.Decimal.  A short search revealed that many other people have been having the problem as well, in their own apache/wsgi implementations (django, mostly), but I found no real solutions among the posts I read.  So I did some experimentation of my own.<br>

<br>
The following code will break unexpectedly on standard python2.7 (and earlier) because of the way that isinstance fails after reload() (which is called by both of the above web frameworks).<br>
<br>
This is the error: TypeError("Cannot convert %r to Decimal" % value)<br>
<br>
THE TEST CODE<br>
<br>
import decimal<br>
from decimal import Decimal<br>
<br>
#this works<br>
Decimal(Decimal())<br>
<br>
reload(decimal)<br>
<br>
#this fails before patching, but works fine afterwards<br>
Decimal(Decimal())<br>
<br>
</blockquote>
<br>
Patching decimal.py to make it work with reload() is probably not going to happen.<br>
<br>
What you should be doing is:<br>
<br>
  import decimal<br>
  from decimal import Decimal<br>
<br>
  reload(decimal)<br>
  Decimal = decimal.Decimal   # (rebind 'Decimal' to the reloaded code)<span class="HOEnZb"><font color="#888888"><br>
<br>
~Ethan~<br>
</font></span></blockquote></div><br></div></div>