[issue8613] Decimal module flags undetermined when a signal is trapped.

Mark Dickinson report at bugs.python.org
Wed May 5 14:27:59 CEST 2010


Mark Dickinson <dickinsm at gmail.com> added the comment:

Yes, that's a good point.  It would be nice for e.g. "Inexact => Rounded" invariants to be, well, invariant.

I agree that the cdecimal behaviour is the correct one.  I'm looking for wiggle room here because I don't really want to make a set of complicated and possibly performance-degrading changes to the decimal module unless it's really necessary for correctness.

Having said that, I can see at least one reasonable way of fixing this in the decimal module:

(1) Create a "delay_traps" context manager, so that:

with delay_traps():
    <do arithmetic>

disables traps for the duration of the with block, keeps track of all flags set (disregarding those set before the with block was entered), and then on leaving the with block re-raises signals corresponding to the traps set in the original context (respecting precedence, of course).

(2) Also create a "_delayed_traps" (names could do with improvement, probably) decorator that effectively wraps an entire function in 'with delay_traps()"

(3) Decorate all the primitive decimal operations with this decorator.

Thoughts?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8613>
_______________________________________


More information about the Python-bugs-list mailing list