[Python-Dev] decimal.py signals & traps (original) (raw)
Raymond Hettinger python at rcn.com
Mon Jul 12 05:11:57 CEST 2004
- Previous message: [Python-Dev] decimal.py signals & traps
- Next message: [Python-Dev] decimal.py signals & traps
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Raymond writes: > I would like change the Context constructor API to [...] > (list only the flags and traps that you want set).
[Jim]
I assume there will still be a reasonable way to say both
Yes.
"Keep the context just as it is, but turn off flag/trap X" "Keep the context just as it is, but turn on flag/trap X"
After simplifying the constructor and altering the representation to match, there was no longer much of a need to try to hide the dictionary with a bunch of methods. Since everyone already knows how to use a dictionary, the API is easier to learn without method access to traps and flags:
c = Context(prec=7, traps=[DivisionByZero, Overflow]) c Context(prec=7, rounding=ROUND_HALF_EVEN, Emin=-999999999, Emax=999999999, capitals=1, flags=[], traps=[DivisionByZero, Overflow]) c.traps[Overflow] = 0 c Context(prec=7, rounding=ROUND_HALF_EVEN, Emin=-999999999, Emax=999999999, capitals=1, flags=[], traps=[DivisionByZero])
As a nice side benefit, eval(repr(c)) now works too.
Privatizing the dictionary can still be done but I don't think it is worth adding more methods and slowing everything down with an additional layer of indirection.
Raymond
- Previous message: [Python-Dev] decimal.py signals & traps
- Next message: [Python-Dev] decimal.py signals & traps
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]