Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd7f76d

Browse files
committed
Tim gets his default traps.
1 parent 4e0e1b6 commit bd7f76d

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

Lib/decimal.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
Here are some examples of using the decimal module:
3232
3333
>>> from decimal import *
34-
>>> getcontext().prec=9
34+
>>> setcontext(ExtendedContext)
3535
>>> Decimal(0)
3636
Decimal("0")
3737
>>> Decimal("1")
@@ -405,8 +405,8 @@ def _filterfunc(obj):
405405

406406
def setcontext(context):
407407
"""Set this thread's context to context."""
408-
if context == DefaultContext:
409-
context = Context()
408+
if context in (DefaultContext, BasicContext, ExtendedContext):
409+
context = context.copy()
410410
threading.currentThread().__decimal_context__ = context
411411

412412
def getcontext():
@@ -2960,28 +2960,30 @@ def _isnan(num):
29602960

29612961
##### Setup Specific Contexts ################################
29622962

2963-
_basic_traps = dict.fromkeys(Signals, 1)
2964-
_basic_traps.update({Inexact:0, Rounded:0, Subnormal:0})
2965-
29662963
# The default context prototype used by Context()
29672964
# Is mutable, so than new contexts can have different default values
29682965

2966+
_default_traps = dict.fromkeys(Signals, 0)
2967+
_default_traps.update({DivisionByZero:1, Overflow:1, InvalidOperation:1})
2968+
29692969
DefaultContext = Context(
29702970
prec=28, rounding=ROUND_HALF_EVEN,
2971-
trap_enablers=dict.fromkeys(Signals, 0),
2971+
trap_enablers=_default_traps,
29722972
flags=None,
29732973
_rounding_decision=ALWAYS_ROUND,
29742974
Emax=DEFAULT_MAX_EXPONENT,
29752975
Emin=DEFAULT_MIN_EXPONENT,
29762976
capitals=1
29772977
)
2978-
DefaultContext.trap_enablers.update({ConversionSyntax : 1})
29792978

29802979
# Pre-made alternate contexts offered by the specification
29812980
# Don't change these; the user should be able to select these
29822981
# contexts and be able to reproduce results from other implementations
29832982
# of the spec.
29842983

2984+
_basic_traps = dict.fromkeys(Signals, 1)
2985+
_basic_traps.update({Inexact:0, Rounded:0, Subnormal:0})
2986+
29852987
BasicContext = Context(
29862988
prec=9, rounding=ROUND_HALF_UP,
29872989
trap_enablers=_basic_traps,

0 commit comments

Comments
 (0)