Skip to content

Commit 4a5a3f1

Browse files
Trim _defer_traps prose and drop an unrelated comment reflow
1 parent 324e70e commit 4a5a3f1

1 file changed

Lines changed: 9 additions & 22 deletions

File tree

‎Lib/_pydecimal.py‎

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,8 +1775,7 @@ def _fix(self, context):
17751775
exp_min += 1
17761776

17771777
with context._defer_traps():
1778-
# check whether the rounding pushed the exponent out
1779-
# of range
1778+
# check if rounding pushed the exponent out of range
17801779
if exp_min > Etop:
17811780
ans = context._raise_error(Overflow, 'above Emax',
17821781
self._sign)
@@ -4002,9 +4001,8 @@ def __init__(self, prec=None, rounding=None, Emin=None, Emax=None,
40024001
else:
40034002
self._ignored_flags = _ignored_flags
40044003

4005-
# State for _defer_traps: the nesting level of deferral blocks
4006-
# and the first trapped exception waiting to be raised by the
4007-
# outermost block. Transient: not copied or pickled.
4004+
# _defer_traps state: nesting level and the deferred exception.
4005+
# Transient: not copied or pickled.
40084006
self._deferred_traps = 0
40094007
self._deferred_error = None
40104008

@@ -4155,12 +4153,9 @@ def _raise_error(self, condition, explanation = None, *args):
41554153
return condition().handle(self, *args)
41564154

41574155
if self._deferred_traps:
4158-
# A _defer_traps block is recording the signals of a
4159-
# multi-signal operation: remember the first trapped
4160-
# exception instead of raising it now, so that the
4161-
# remaining signals can still set their flags. The block
4162-
# raises it on exit. Return the default response, exactly
4163-
# as if the signal had not been trapped.
4156+
# Inside a _defer_traps block: record the first trapped
4157+
# exception instead of raising it, and return the default
4158+
# response as if the signal had not been trapped.
41644159
if self._deferred_error is None:
41654160
self._deferred_error = error(explanation)
41664161
return condition().handle(self, *args)
@@ -4173,17 +4168,9 @@ def _raise_error(self, condition, explanation = None, *args):
41734168
def _defer_traps(self):
41744169
"""Defer trapped signals until the end of the with block.
41754170
4176-
Some operations signal several conditions at once (for
4177-
example, Overflow together with Inexact and Rounded). The
4178-
specification requires the flag of every condition encountered
4179-
to be set, and the C implementation records the full set of
4180-
flags before raising a trapped exception. Within this block,
4181-
_raise_error does the same: it sets the flag of each signal
4182-
and returns its default response, and the first trapped
4183-
exception (in the order the signals are raised, which is the
4184-
precedence order of the specification) is raised when the
4185-
outermost block exits. If the block raises another exception,
4186-
any deferred exception is discarded.
4171+
_raise_error sets the flag of every signal in the block and
4172+
raises the first trapped exception on exit, so that a
4173+
multi-signal operation sets the same flags as _decimal.
41874174
"""
41884175
self._deferred_traps += 1
41894176
try:

0 commit comments

Comments
 (0)