[Python-Dev] Py2.5 issue: decimal context manager misimplemented, misdesigned, and misdocumented
Phillip J. Eby
pje at telecommunity.com
Wed Aug 30 02:40:00 CEST 2006
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:
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.
More information about the Python-Dev
mailing list