mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
* Update the test suite to reflect that ConversionSyntax was no longer
public. * Removed the non-signal conditions from __all__. * Removed the XXX comment which was resolved. * Use ^ instead of operator.xor * Remove the threading lock which is no longer necessary.
This commit is contained in:
parent
5aa478badf
commit
d87ac8f24d
2 changed files with 6 additions and 18 deletions
|
@ -114,10 +114,8 @@ __all__ = [
|
||||||
'DefaultContext', 'BasicContext', 'ExtendedContext',
|
'DefaultContext', 'BasicContext', 'ExtendedContext',
|
||||||
|
|
||||||
# Exceptions
|
# Exceptions
|
||||||
'DecimalException', 'Clamped', 'InvalidOperation', 'ConversionSyntax',
|
'DecimalException', 'Clamped', 'InvalidOperation', 'DivisionByZero',
|
||||||
'DivisionByZero', 'DivisionImpossible', 'DivisionUndefined',
|
'Inexact', 'Rounded', 'Subnormal', 'Overflow', 'Underflow',
|
||||||
'Inexact', 'InvalidContext', 'Rounded', 'Subnormal', 'Overflow',
|
|
||||||
'Underflow',
|
|
||||||
|
|
||||||
# Constants for use in setting up contexts
|
# Constants for use in setting up contexts
|
||||||
'ROUND_DOWN', 'ROUND_HALF_UP', 'ROUND_HALF_EVEN', 'ROUND_CEILING',
|
'ROUND_DOWN', 'ROUND_HALF_UP', 'ROUND_HALF_EVEN', 'ROUND_CEILING',
|
||||||
|
@ -211,12 +209,6 @@ class InvalidOperation(DecimalException):
|
||||||
return Decimal( (args[1]._sign, args[1]._int, 'n') )
|
return Decimal( (args[1]._sign, args[1]._int, 'n') )
|
||||||
return NaN
|
return NaN
|
||||||
|
|
||||||
# XXX Is there a logic error in subclassing InvalidOperation?
|
|
||||||
# Setting the InvalidOperation trap to zero does not preclude ConversionSyntax.
|
|
||||||
# Also, incrementing Conversion syntax flag will not increment InvalidOperation.
|
|
||||||
# Both of these issues interfere with cross-language portability because
|
|
||||||
# code following the spec would not know about the Python subclasses.
|
|
||||||
|
|
||||||
class ConversionSyntax(InvalidOperation):
|
class ConversionSyntax(InvalidOperation):
|
||||||
"""Trying to convert badly formed string.
|
"""Trying to convert badly formed string.
|
||||||
|
|
||||||
|
@ -1032,7 +1024,7 @@ class Decimal(object):
|
||||||
if ans:
|
if ans:
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
resultsign = operator.xor(self._sign, other._sign)
|
resultsign = self._sign ^ other._sign
|
||||||
if self._isinfinity():
|
if self._isinfinity():
|
||||||
if not other:
|
if not other:
|
||||||
return context._raise_error(InvalidOperation, '(+-)INF * 0')
|
return context._raise_error(InvalidOperation, '(+-)INF * 0')
|
||||||
|
@ -1126,7 +1118,7 @@ class Decimal(object):
|
||||||
else:
|
else:
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
sign = operator.xor(self._sign, other._sign)
|
sign = self._sign ^ other._sign
|
||||||
if not self and not other:
|
if not self and not other:
|
||||||
if divmod:
|
if divmod:
|
||||||
return context._raise_error(DivisionUndefined, '0 / 0', 1)
|
return context._raise_error(DivisionUndefined, '0 / 0', 1)
|
||||||
|
@ -2117,8 +2109,6 @@ class Context(object):
|
||||||
_clamp - If 1, change exponents if too high (Default 0)
|
_clamp - If 1, change exponents if too high (Default 0)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
DefaultLock = threading.Lock()
|
|
||||||
|
|
||||||
def __init__(self, prec=None, rounding=None,
|
def __init__(self, prec=None, rounding=None,
|
||||||
trap_enablers=None, flags=None,
|
trap_enablers=None, flags=None,
|
||||||
_rounding_decision=None,
|
_rounding_decision=None,
|
||||||
|
@ -2127,13 +2117,11 @@ class Context(object):
|
||||||
_ignored_flags=[]):
|
_ignored_flags=[]):
|
||||||
if flags is None:
|
if flags is None:
|
||||||
flags = dict.fromkeys(Signals, 0)
|
flags = dict.fromkeys(Signals, 0)
|
||||||
self.DefaultLock.acquire()
|
|
||||||
for name, val in locals().items():
|
for name, val in locals().items():
|
||||||
if val is None:
|
if val is None:
|
||||||
setattr(self, name, copy.copy(getattr(DefaultContext, name)))
|
setattr(self, name, copy.copy(getattr(DefaultContext, name)))
|
||||||
else:
|
else:
|
||||||
setattr(self, name, val)
|
setattr(self, name, val)
|
||||||
self.DefaultLock.release()
|
|
||||||
del self.self
|
del self.self
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|
|
@ -134,7 +134,7 @@ class DecimalTest(unittest.TestCase):
|
||||||
#print line
|
#print line
|
||||||
try:
|
try:
|
||||||
t = self.eval_line(line)
|
t = self.eval_line(line)
|
||||||
except ConversionSyntax:
|
except InvalidOperation:
|
||||||
print 'Error in test cases:'
|
print 'Error in test cases:'
|
||||||
print line
|
print line
|
||||||
continue
|
continue
|
||||||
|
@ -189,7 +189,7 @@ class DecimalTest(unittest.TestCase):
|
||||||
ans = L[0]
|
ans = L[0]
|
||||||
exceptions = L[1:]
|
exceptions = L[1:]
|
||||||
except (TypeError, AttributeError, IndexError):
|
except (TypeError, AttributeError, IndexError):
|
||||||
raise ConversionSyntax
|
raise InvalidOperation
|
||||||
def FixQuotes(val):
|
def FixQuotes(val):
|
||||||
val = val.replace("''", 'SingleQuote').replace('""', 'DoubleQuote')
|
val = val.replace("''", 'SingleQuote').replace('""', 'DoubleQuote')
|
||||||
val = val.replace("'", '').replace('"', '')
|
val = val.replace("'", '').replace('"', '')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue