![](https://secure.gravatar.com/avatar/bff91e6384fa1818f0f231adf6f7e809.jpg?s=120&d=mm&r=g)
Phillip J. Eby wrote:
At 05:20 PM 8/29/2006 -0700, Raymond Hettinger wrote:
* The implementation's doc string examples were not tested and don't work (this is a deep error). One reads:
with decimal.getcontext() as ctx: ctx.prec += 2 s = ... return +s
To get this to work with the current implementation, it should read
with decimal.getcontext().copy().get_manager() as ctx: ctx.prec += 2 s = ... return +s
This is horrid. Please either revert the patch or fix it to match PEP-343.
Actually, as I read the code, that would be:
with decimal.getcontext().get_manager() as ctx:
Given the current mis-implementation, the copy() step is absolutely necessary. Since context objects are mutable, the current context would never get it precision and flags restored. Try running the example and printing out the current context precision before and after the with-suite. You'll see that the context has changed (which defeats the whole purpose).
Which is still horrible, but unfortunately Guido has already pronounced that __context__ must be removed from PEP 343, which is what caused this abomination to come about.
The PEP currently offers the idea of a 'localcontext()' API that provides a nicer spelling, but it appears nobody implemented it.
Right. The PEP version was correct and desirable. But at this point, it is better to have nothing at all. Users can still write their own (a la example 8 in the PEP). I do not want the decimal API to be forever mucked-up; hence, we should revert the change. Since it is buggy, that makes the decision an easy one to swallow. Raymond