]> granicus.if.org Git - python/commitdiff
* Rename "Signals" to "_signals" making it non-public.
authorRaymond Hettinger <python@rcn.com>
Wed, 14 Jul 2004 15:41:57 +0000 (15:41 +0000)
committerRaymond Hettinger <python@rcn.com>
Wed, 14 Jul 2004 15:41:57 +0000 (15:41 +0000)
* Context.create_decimal can take a zero default just like Decimal().
* Fix typo in comment.

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

index 85e0f3410b427cf093c89751100932a73f98c2e2..88fa031c297a02ba0cd49257d5ac70e7a6513099 100644 (file)
@@ -120,7 +120,6 @@ __all__ = [
     # Constants for use in setting up contexts
     'ROUND_DOWN', 'ROUND_HALF_UP', 'ROUND_HALF_EVEN', 'ROUND_CEILING',
     'ROUND_FLOOR', 'ROUND_UP', 'ROUND_HALF_DOWN',
-    'Signals',    # <-- Used for building trap/flag dictionaries
 
     # Functions for manipulating contexts
     'setcontext', 'getcontext'
@@ -368,7 +367,7 @@ class Underflow(Inexact, Rounded, Subnormal):
     """
 
 # List of public traps and flags
-Signals = [Clamped, DivisionByZero, Inexact, Overflow, Rounded,
+_signals = [Clamped, DivisionByZero, Inexact, Overflow, Rounded,
            Underflow, InvalidOperation, Subnormal]
 
 # Map conditions (per the spec) to signals
@@ -2120,9 +2119,9 @@ class Context(object):
                  capitals=None, _clamp=0,
                  _ignored_flags=[]):
         if not isinstance(flags, dict):
-            flags = dict([(s,s in flags) for s in Signals])
+            flags = dict([(s,s in flags) for s in _signals])
         if traps is not None and not isinstance(traps, dict):
-            traps = dict([(s,s in traps) for s in Signals])
+            traps = dict([(s,s in traps) for s in _signals])
         for name, val in locals().items():
             if val is None:
                 setattr(self, name, copy.copy(getattr(DefaultContext, name)))
@@ -2175,7 +2174,7 @@ class Context(object):
 
     def _ignore_all_flags(self):
         """Ignore all flags, if they are raised"""
-        return self._ignore_flags(*Signals)
+        return self._ignore_flags(*_signals)
 
     def _ignore_flags(self, *flags):
         """Ignore the flags, if they are raised"""
@@ -2244,7 +2243,7 @@ class Context(object):
         self.rounding= type
         return rounding
 
-    def create_decimal(self, num):
+    def create_decimal(self, num='0'):
         """Creates a new Decimal instance but using self as context."""
         d = Decimal(num, context=self)
         return d._fix(context=self)
@@ -2950,7 +2949,7 @@ def _isnan(num):
 ##### Setup Specific Contexts ################################
 
 # The default context prototype used by Context()
-# Is mutable, so than new contexts can have different default values
+# Is mutable, so that new contexts can have different default values
 
 DefaultContext = Context(
         prec=28, rounding=ROUND_HALF_EVEN,
index 6354063eb55189863844352fdebd92f2dc3b2583..2415a78c6e812d1b98b7947fb171c5a8f7b07b22 100644 (file)
@@ -35,6 +35,9 @@ from test.test_support import TestSkipped, run_unittest, run_doctest, is_resourc
 import threading
 import random
 
+# Useful Test Constant
+Signals = getcontext().flags.keys()
+
 # Tests are built around these assumed context defaults
 DefaultContext.prec=9
 DefaultContext.rounding=ROUND_HALF_EVEN
@@ -480,7 +483,10 @@ class DecimalExplicitConstructionTest(unittest.TestCase):
         nc.prec = 3
 
         # empty
-        self.assertRaises(TypeError, nc.create_decimal)
+        d = Decimal()
+        self.assertEqual(str(d), '0')
+        d = nc.create_decimal()
+        self.assertEqual(str(d), '0')
 
         # from None
         self.assertRaises(TypeError, nc.create_decimal, None)