@@ -1650,7 +1650,7 @@ def _fix(self, context):
16501650 self = _dec_from_triple (self ._sign , '1' , exp_min - 1 )
16511651 digits = 0
16521652 rounding_method = self ._pick_rounding_function [context .rounding ]
1653- changed = getattr (self , rounding_method )( digits )
1653+ changed = rounding_method (self , digits )
16541654 coeff = self ._int [:digits ] or '0'
16551655 if changed > 0 :
16561656 coeff = str (int (coeff )+ 1 )
@@ -1690,8 +1690,6 @@ def _fix(self, context):
16901690 # here self was representable to begin with; return unchanged
16911691 return Decimal (self )
16921692
1693- _pick_rounding_function = {}
1694-
16951693 # for each of the rounding functions below:
16961694 # self is a finite, nonzero Decimal
16971695 # prec is an integer satisfying 0 <= prec < len(self._int)
@@ -1758,6 +1756,17 @@ def _round_05up(self, prec):
17581756 else :
17591757 return - self ._round_down (prec )
17601758
1759+ _pick_rounding_function = dict (
1760+ ROUND_DOWN = _round_down ,
1761+ ROUND_UP = _round_up ,
1762+ ROUND_HALF_UP = _round_half_up ,
1763+ ROUND_HALF_DOWN = _round_half_down ,
1764+ ROUND_HALF_EVEN = _round_half_even ,
1765+ ROUND_CEILING = _round_ceiling ,
1766+ ROUND_FLOOR = _round_floor ,
1767+ ROUND_05UP = _round_05up ,
1768+ )
1769+
17611770 def __round__ (self , n = None ):
17621771 """Round self to the nearest integer, or to a given precision.
17631772
@@ -2554,8 +2563,8 @@ def _rescale(self, exp, rounding):
25542563 if digits < 0 :
25552564 self = _dec_from_triple (self ._sign , '1' , exp - 1 )
25562565 digits = 0
2557- this_function = getattr ( self , self ._pick_rounding_function [rounding ])
2558- changed = this_function (digits )
2566+ this_function = self ._pick_rounding_function [rounding ]
2567+ changed = this_function (self , digits )
25592568 coeff = self ._int [:digits ] or '0'
25602569 if changed == 1 :
25612570 coeff = str (int (coeff )+ 1 )
@@ -3767,18 +3776,6 @@ def _dec_from_triple(sign, coefficient, exponent, special=False):
37673776
37683777##### Context class #######################################################
37693778
3770-
3771- # get rounding method function:
3772- rounding_functions = [name for name in Decimal .__dict__ .keys ()
3773- if name .startswith ('_round_' )]
3774- for name in rounding_functions :
3775- # name is like _round_half_even, goes to the global ROUND_HALF_EVEN value.
3776- globalname = name [1 :].upper ()
3777- val = globals ()[globalname ]
3778- Decimal ._pick_rounding_function [val ] = name
3779-
3780- del name , val , globalname , rounding_functions
3781-
37823779class _ContextManager (object ):
37833780 """Context manager class to support localcontext().
37843781
0 commit comments