[Python-Dev] decimal.py signals & traps
python at rcn.com
Thu Jul 8 13:38:54 CEST 2004
> Please take a look at the patch I submitted to SourceForge:
> <http://python.org/sf/987300>. decimal.Signals is changed to list
> signals, not conditions. Context._raise_error is modified to handle
> signals properly.
This should be tackled in steps and as part of larger improvement to the
The most uncomfortable part of the Python interface to contexts is
creating the dictionaries for traps and flags arguments. Besides being
a pain to create and display, there are issues with two contexts sharing
the same underlying dictionaries. Also, it makes it difficult to
address the issue at hand (as noted by the one XXX comment in the module
and by your bug report).
As a first step, I would like change the Context constructor API to
match the format in Context.__repr__. That format is somewhat easier to
use and less verbose (list only the flags and traps that you want set).
Also, I would add accessor methods patterned after the Language
Independent Arithmetic standard (LIA-1) to set, clear, and test flags
and traps. The dictionaries themselves would be made private (allowing
them to be recast as sets if desired).
With a method interface in place, a next step would be to add logic to
maintain relationships between signals. Setting the ConversionSyntax
flag also sets the InvalidOperation flag. Likewise setting a trap for
InvalidOperation would set the trap for ConversionSyntax.
As a side benefit, the above changes will make it easier to someday
implement the module in C. Holding user supplied, volatile dictionaries
was not a recipe for success in that regard.
I'm less enthusiastic about changing any of the exception names but none
of the above precludes that as a last step.
More information about the Python-Dev