]> granicus.if.org Git - python/commitdiff
* Update the test suite to reflect that ConversionSyntax was no longer
authorRaymond Hettinger <python@rcn.com>
Fri, 9 Jul 2004 10:52:54 +0000 (10:52 +0000)
committerRaymond Hettinger <python@rcn.com>
Fri, 9 Jul 2004 10:52:54 +0000 (10:52 +0000)
  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.

Lib/decimal.py
Lib/test/test_decimal.py

index 9f77b248fc16970014639038701a1f5b394ba8e9..d9c3f100c18b9025d3e98a09f998ebabe19247d9 100644 (file)
@@ -114,10 +114,8 @@ __all__ = [
     'DefaultContext', 'BasicContext', 'ExtendedContext',
 
     # Exceptions
-    'DecimalException', 'Clamped', 'InvalidOperation', 'ConversionSyntax',
-    'DivisionByZero', 'DivisionImpossible', 'DivisionUndefined',
-    'Inexact', 'InvalidContext', 'Rounded', 'Subnormal', 'Overflow',
-    'Underflow',
+    'DecimalException', 'Clamped', 'InvalidOperation', 'DivisionByZero',
+    'Inexact', 'Rounded', 'Subnormal', 'Overflow', 'Underflow',
 
     # Constants for use in setting up contexts
     '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 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):
     """Trying to convert badly formed string.
 
@@ -1032,7 +1024,7 @@ class Decimal(object):
         if ans:
             return ans
 
-        resultsign = operator.xor(self._sign, other._sign)
+        resultsign = self._sign ^ other._sign
         if self._isinfinity():
             if not other:
                 return context._raise_error(InvalidOperation, '(+-)INF * 0')
@@ -1126,7 +1118,7 @@ class Decimal(object):
             else:
                 return ans
 
-        sign = operator.xor(self._sign, other._sign)
+        sign = self._sign ^ other._sign
         if not self and not other:
             if divmod:
                 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)
     """
 
-    DefaultLock = threading.Lock()
-
     def __init__(self, prec=None, rounding=None,
                  trap_enablers=None, flags=None,
                  _rounding_decision=None,
@@ -2127,13 +2117,11 @@ class Context(object):
                  _ignored_flags=[]):
         if flags is None:
             flags = dict.fromkeys(Signals, 0)
-        self.DefaultLock.acquire()
         for name, val in locals().items():
             if val is None:
                 setattr(self, name, copy.copy(getattr(DefaultContext, name)))
             else:
                 setattr(self, name, val)
-        self.DefaultLock.release()
         del self.self
 
     def __repr__(self):
index e6d93896f62db7a2c42f9790cf727eab56d3c9f8..dc202f3109caaf15f8ea37284adaaa165619ac95 100644 (file)
@@ -134,7 +134,7 @@ class DecimalTest(unittest.TestCase):
             #print line
             try:
                 t = self.eval_line(line)
-            except ConversionSyntax:
+            except InvalidOperation:
                 print 'Error in test cases:'
                 print line
                 continue
@@ -189,7 +189,7 @@ class DecimalTest(unittest.TestCase):
             ans = L[0]
             exceptions = L[1:]
         except (TypeError, AttributeError, IndexError):
-            raise ConversionSyntax
+            raise InvalidOperation
         def FixQuotes(val):
             val = val.replace("''", 'SingleQuote').replace('""', 'DoubleQuote')
             val = val.replace("'", '').replace('"', '')