[Python-checkins] cpython (2.7): Issue #11830: Remove unnecessary introspection code in the decimal module.

raymond.hettinger python-checkins at python.org
Tue Apr 12 02:28:02 CEST 2011


http://hg.python.org/cpython/rev/b4b1f557d563
changeset:   69263:b4b1f557d563
branch:      2.7
parent:      69256:a280672d3d8d
user:        Raymond Hettinger <python at rcn.com>
date:        Mon Apr 11 17:27:42 2011 -0700
summary:
  Issue #11830: Remove unnecessary introspection code in the decimal module.
It was causing a failed import in the Turkish locale where the locale
sensitive str.upper() method caused a name mismatch.

files:
  Lib/decimal.py |  25 +++++++++++--------------
  Misc/NEWS      |   4 ++++
  2 files changed, 15 insertions(+), 14 deletions(-)


diff --git a/Lib/decimal.py b/Lib/decimal.py
--- a/Lib/decimal.py
+++ b/Lib/decimal.py
@@ -1723,8 +1723,6 @@
         # here self was representable to begin with; return unchanged
         return Decimal(self)
 
-    _pick_rounding_function = {}
-
     # for each of the rounding functions below:
     #   self is a finite, nonzero Decimal
     #   prec is an integer satisfying 0 <= prec < len(self._int)
@@ -1791,6 +1789,17 @@
         else:
             return -self._round_down(prec)
 
+    _pick_rounding_function = dict(
+        ROUND_DOWN = '_round_down',
+        ROUND_UP = '_round_up',
+        ROUND_HALF_UP = '_round_half_up',
+        ROUND_HALF_DOWN = '_round_half_down',
+        ROUND_HALF_EVEN = '_round_half_even',
+        ROUND_CEILING = '_round_ceiling',
+        ROUND_FLOOR = '_round_floor',
+        ROUND_05UP = '_round_05up',
+    )
+
     def fma(self, other, third, context=None):
         """Fused multiply-add.
 
@@ -3708,18 +3717,6 @@
 
 ##### Context class #######################################################
 
-
-# get rounding method function:
-rounding_functions = [name for name in Decimal.__dict__.keys()
-                                    if name.startswith('_round_')]
-for name in rounding_functions:
-    # name is like _round_half_even, goes to the global ROUND_HALF_EVEN value.
-    globalname = name[1:].upper()
-    val = globals()[globalname]
-    Decimal._pick_rounding_function[val] = name
-
-del name, val, globalname, rounding_functions
-
 class _ContextManager(object):
     """Context manager class to support localcontext().
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -57,6 +57,10 @@
 - Issue #4877: Fix a segfault in xml.parsers.expat while attempting to parse
   a closed file.
 
+- Issue #11830: Remove unnecessary introspection code in the decimal module.
+  It was causing a failed import in the Turkish locale where the locale
+  sensitive str.upper() method caused a name mismatch.
+
 - Issue #8428: Fix a race condition in multiprocessing.Pool when terminating
   worker processes: new processes would be spawned while the pool is being
   shut down.  Patch by Charles-François Natali.

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list