<div dir="ltr">Meant to copy list on reply, sorry.<br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Karen Tracey</b> &lt;<a href="mailto:kmtracey@gmail.com">kmtracey@gmail.com</a>&gt;<br>
Date: Fri, Jul 18, 2008 at 11:48 PM<br>Subject: Re: [Python-Dev] Change in repr of Decimal in 2.6<br>To: Raymond Hettinger &lt;<a href="mailto:python@rcn.com">python@rcn.com</a>&gt;<br><br><br><div dir="ltr"><div class="Ih2E3d">
On Fri, Jul 18, 2008 at 11:19 PM, Raymond Hettinger &lt;<a href="mailto:python@rcn.com" target="_blank">python@rcn.com</a>&gt; wrote:<br></div><div class="gmail_quote"><div class="Ih2E3d"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

From: Karen Tracey <br><div>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I noticed when trying out Python&#39;s 2.6b2 release that the repr of Decimal has changed since 2.5. &nbsp;On 2.5:<br>
</blockquote></div>
...<div><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
&nbsp;quotes were used whereas on 2.6b2:<br>
</blockquote></div>
...<div><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
single quotes are used. &nbsp;Searching around I see this was done in r60773 with the log message:<br>
Fix decimal repr which should have used single quotes like other reprs.<br>
<br>
but I can&#39;t find any discussion other than that. &nbsp;<br>
</blockquote>
<br></div>
Guido requested this change so that the Decimal repr would match the style used elsewhere (i.e. str(7) --&gt; &#39;7&#39;).<div><br></div></blockquote></div><div><br>Thanks for the background.&nbsp; Can&#39;t say I ever noticed the inconsistency myself.<br>

&nbsp;</div><div class="Ih2E3d"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
If it&#39;s here to stay, is there some straightforward way that I am unaware of to construct tests that use Decimal repr but will work correctly on Python 2.3-2.6?<br>
</blockquote>
<br></div>
A quick hack is to monkey patch the decimal module:<br>
<br>
 &nbsp; &gt;&gt;&gt; import decimal<br>
 &nbsp; &gt;&gt;&gt; decimal.Decimal.__repr__ = lambda s: &#39;Decimal(&quot;%s&quot;)&#39; % str(s)<br>
</blockquote></div><div><br>That is quick, but does seem hackish.<br><br></div><div class="Ih2E3d"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
A better fix is to amend to doctests to not rely on the __repr__ format.<br>
Instead of:<br>
<br>
 &nbsp;&gt;&gt;&gt; Decimal(&#39;7.1&#39;)<br>
 &nbsp;Decimal(&quot;7.1&quot;)<br>
<br>
use:<br>
<br>
 &nbsp;&gt;&gt;&gt; print Decimal(&#39;7.1&#39;)<br>
 &nbsp;7.1<br>
</blockquote></div><div><br>Yeah, but the testcases are not quite that simple.&nbsp; They&#39;re often testing return values from functions and as much verifying that the type is correct as the value, so I think I&#39;d have to change stuff like:<br>

<br>&gt;&gt;&gt; f.clean(&#39;1&#39;)<br>Decimal(&quot;1&quot;)<br><br>to:<br><br>&gt;&gt;&gt; x = f.clean(&#39;1&#39;)<br>&gt;&gt;&gt; print type(x), x<br>&lt;class &#39;decimal.Decimal&#39;&gt; 1<br>&nbsp;<br></div></div>right?&nbsp; <br>

<br>Thanks for the answer,<br>Karen<br></div>
</div><br></div>