Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f923641

Browse files
committed
Merged revisions 68182 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r68182 | mark.dickinson | 2009-01-02 23:07:08 +0000 (Fri, 02 Jan 2009) | 4 lines Issue #4812: add missing underscore prefix to some internal-use-only constants in the decimal module. (Dec_0 becomes _Dec_0, etc.) ........
1 parent ad9d96b commit f923641

2 files changed

Lines changed: 66 additions & 63 deletions

File tree

Lib/decimal.py

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def handle(self, context, *args):
217217
if args:
218218
ans = _dec_from_triple(args[0]._sign, args[0]._int, 'n', True)
219219
return ans._fix_nan(context)
220-
return NaN
220+
return _NaN
221221

222222
class ConversionSyntax(InvalidOperation):
223223
"""Trying to convert badly formed string.
@@ -227,7 +227,7 @@ class ConversionSyntax(InvalidOperation):
227227
syntax. The result is [0,qNaN].
228228
"""
229229
def handle(self, context, *args):
230-
return NaN
230+
return _NaN
231231

232232
class DivisionByZero(DecimalException, ZeroDivisionError):
233233
"""Division by 0.
@@ -243,7 +243,7 @@ class DivisionByZero(DecimalException, ZeroDivisionError):
243243
"""
244244

245245
def handle(self, context, sign, *args):
246-
return Infsign[sign]
246+
return _Infsign[sign]
247247

248248
class DivisionImpossible(InvalidOperation):
249249
"""Cannot perform the division adequately.
@@ -254,7 +254,7 @@ class DivisionImpossible(InvalidOperation):
254254
"""
255255

256256
def handle(self, context, *args):
257-
return NaN
257+
return _NaN
258258

259259
class DivisionUndefined(InvalidOperation, ZeroDivisionError):
260260
"""Undefined result of division.
@@ -265,7 +265,7 @@ class DivisionUndefined(InvalidOperation, ZeroDivisionError):
265265
"""
266266

267267
def handle(self, context, *args):
268-
return NaN
268+
return _NaN
269269

270270
class Inexact(DecimalException):
271271
"""Had to round, losing information.
@@ -291,7 +291,7 @@ class InvalidContext(InvalidOperation):
291291
"""
292292

293293
def handle(self, context, *args):
294-
return NaN
294+
return _NaN
295295

296296
class Rounded(DecimalException):
297297
"""Number got rounded (not necessarily changed during rounding).
@@ -341,15 +341,15 @@ class Overflow(Inexact, Rounded):
341341
def handle(self, context, sign, *args):
342342
if context.rounding in (ROUND_HALF_UP, ROUND_HALF_EVEN,
343343
ROUND_HALF_DOWN, ROUND_UP):
344-
return Infsign[sign]
344+
return _Infsign[sign]
345345
if sign == 0:
346346
if context.rounding == ROUND_CEILING:
347-
return Infsign[sign]
347+
return _Infsign[sign]
348348
return _dec_from_triple(sign, '9'*context.prec,
349349
context.Emax-context.prec+1)
350350
if sign == 1:
351351
if context.rounding == ROUND_FLOOR:
352-
return Infsign[sign]
352+
return _Infsign[sign]
353353
return _dec_from_triple(sign, '9'*context.prec,
354354
context.Emax-context.prec+1)
355355

@@ -1173,12 +1173,12 @@ def __mul__(self, other, context=None):
11731173
if self._isinfinity():
11741174
if not other:
11751175
return context._raise_error(InvalidOperation, '(+-)INF * 0')
1176-
return Infsign[resultsign]
1176+
return _Infsign[resultsign]
11771177

11781178
if other._isinfinity():
11791179
if not self:
11801180
return context._raise_error(InvalidOperation, '0 * (+-)INF')
1181-
return Infsign[resultsign]
1181+
return _Infsign[resultsign]
11821182

11831183
resultexp = self._exp + other._exp
11841184

@@ -1228,7 +1228,7 @@ def __truediv__(self, other, context=None):
12281228
return context._raise_error(InvalidOperation, '(+-)INF/(+-)INF')
12291229

12301230
if self._isinfinity():
1231-
return Infsign[sign]
1231+
return _Infsign[sign]
12321232

12331233
if other._isinfinity():
12341234
context._raise_error(Clamped, 'Division by infinity')
@@ -1328,7 +1328,7 @@ def __divmod__(self, other, context=None):
13281328
ans = context._raise_error(InvalidOperation, 'divmod(INF, INF)')
13291329
return ans, ans
13301330
else:
1331-
return (Infsign[sign],
1331+
return (_Infsign[sign],
13321332
context._raise_error(InvalidOperation, 'INF % x'))
13331333

13341334
if not other:
@@ -1476,7 +1476,7 @@ def __floordiv__(self, other, context=None):
14761476
if other._isinfinity():
14771477
return context._raise_error(InvalidOperation, 'INF // INF')
14781478
else:
1479-
return Infsign[self._sign ^ other._sign]
1479+
return _Infsign[self._sign ^ other._sign]
14801480

14811481
if not other:
14821482
if self:
@@ -1820,12 +1820,12 @@ def fma(self, other, third, context=None):
18201820
if not other:
18211821
return context._raise_error(InvalidOperation,
18221822
'INF * 0 in fma')
1823-
product = Infsign[self._sign ^ other._sign]
1823+
product = _Infsign[self._sign ^ other._sign]
18241824
elif other._exp == 'F':
18251825
if not self:
18261826
return context._raise_error(InvalidOperation,
18271827
'0 * INF in fma')
1828-
product = Infsign[self._sign ^ other._sign]
1828+
product = _Infsign[self._sign ^ other._sign]
18291829
else:
18301830
product = _dec_from_triple(self._sign ^ other._sign,
18311831
str(int(self._int) * int(other._int)),
@@ -2175,7 +2175,7 @@ def __pow__(self, other, modulo=None, context=None):
21752175
if not self:
21762176
return context._raise_error(InvalidOperation, '0 ** 0')
21772177
else:
2178-
return Dec_p1
2178+
return _Dec_p1
21792179

21802180
# result has sign 1 iff self._sign is 1 and other is an odd integer
21812181
result_sign = 0
@@ -2197,19 +2197,19 @@ def __pow__(self, other, modulo=None, context=None):
21972197
if other._sign == 0:
21982198
return _dec_from_triple(result_sign, '0', 0)
21992199
else:
2200-
return Infsign[result_sign]
2200+
return _Infsign[result_sign]
22012201

22022202
# Inf**(+ve or Inf) = Inf; Inf**(-ve or -Inf) = 0
22032203
if self._isinfinity():
22042204
if other._sign == 0:
2205-
return Infsign[result_sign]
2205+
return _Infsign[result_sign]
22062206
else:
22072207
return _dec_from_triple(result_sign, '0', 0)
22082208

22092209
# 1**other = 1, but the choice of exponent and the flags
22102210
# depend on the exponent of self, and on whether other is a
22112211
# positive integer, a negative integer, or neither
2212-
if self == Dec_p1:
2212+
if self == _Dec_p1:
22132213
if other._isinteger():
22142214
# exp = max(self._exp*max(int(other), 0),
22152215
# 1-context.prec) but evaluating int(other) directly
@@ -2242,7 +2242,7 @@ def __pow__(self, other, modulo=None, context=None):
22422242
if (other._sign == 0) == (self_adj < 0):
22432243
return _dec_from_triple(result_sign, '0', 0)
22442244
else:
2245-
return Infsign[result_sign]
2245+
return _Infsign[result_sign]
22462246

22472247
# from here on, the result always goes through the call
22482248
# to _fix at the end of this function.
@@ -2762,9 +2762,9 @@ def compare_total(self, other):
27622762
"""
27632763
# if one is negative and the other is positive, it's easy
27642764
if self._sign and not other._sign:
2765-
return Dec_n1
2765+
return _Dec_n1
27662766
if not self._sign and other._sign:
2767-
return Dec_p1
2767+
return _Dec_p1
27682768
sign = self._sign
27692769

27702770
# let's handle both NaN types
@@ -2774,51 +2774,51 @@ def compare_total(self, other):
27742774
if self_nan == other_nan:
27752775
if self._int < other._int:
27762776
if sign:
2777-
return Dec_p1
2777+
return _Dec_p1
27782778
else:
2779-
return Dec_n1
2779+
return _Dec_n1
27802780
if self._int > other._int:
27812781
if sign:
2782-
return Dec_n1
2782+
return _Dec_n1
27832783
else:
2784-
return Dec_p1
2785-
return Dec_0
2784+
return _Dec_p1
2785+
return _Dec_0
27862786

27872787
if sign:
27882788
if self_nan == 1:
2789-
return Dec_n1
2789+
return _Dec_n1
27902790
if other_nan == 1:
2791-
return Dec_p1
2791+
return _Dec_p1
27922792
if self_nan == 2:
2793-
return Dec_n1
2793+
return _Dec_n1
27942794
if other_nan == 2:
2795-
return Dec_p1
2795+
return _Dec_p1
27962796
else:
27972797
if self_nan == 1:
2798-
return Dec_p1
2798+
return _Dec_p1
27992799
if other_nan == 1:
2800-
return Dec_n1
2800+
return _Dec_n1
28012801
if self_nan == 2:
2802-
return Dec_p1
2802+
return _Dec_p1
28032803
if other_nan == 2:
2804-
return Dec_n1
2804+
return _Dec_n1
28052805

28062806
if self < other:
2807-
return Dec_n1
2807+
return _Dec_n1
28082808
if self > other:
2809-
return Dec_p1
2809+
return _Dec_p1
28102810

28112811
if self._exp < other._exp:
28122812
if sign:
2813-
return Dec_p1
2813+
return _Dec_p1
28142814
else:
2815-
return Dec_n1
2815+
return _Dec_n1
28162816
if self._exp > other._exp:
28172817
if sign:
2818-
return Dec_n1
2818+
return _Dec_n1
28192819
else:
2820-
return Dec_p1
2821-
return Dec_0
2820+
return _Dec_p1
2821+
return _Dec_0
28222822

28232823

28242824
def compare_total_mag(self, other):
@@ -2859,11 +2859,11 @@ def exp(self, context=None):
28592859

28602860
# exp(-Infinity) = 0
28612861
if self._isinfinity() == -1:
2862-
return Dec_0
2862+
return _Dec_0
28632863

28642864
# exp(0) = 1
28652865
if not self:
2866-
return Dec_p1
2866+
return _Dec_p1
28672867

28682868
# exp(Infinity) = Infinity
28692869
if self._isinfinity() == 1:
@@ -3015,15 +3015,15 @@ def ln(self, context=None):
30153015

30163016
# ln(0.0) == -Infinity
30173017
if not self:
3018-
return negInf
3018+
return _negInf
30193019

30203020
# ln(Infinity) = Infinity
30213021
if self._isinfinity() == 1:
3022-
return Inf
3022+
return _Inf
30233023

30243024
# ln(1.0) == 0.0
3025-
if self == Dec_p1:
3026-
return Dec_0
3025+
if self == _Dec_p1:
3026+
return _Dec_0
30273027

30283028
# ln(negative) raises InvalidOperation
30293029
if self._sign == 1:
@@ -3095,11 +3095,11 @@ def log10(self, context=None):
30953095

30963096
# log10(0.0) == -Infinity
30973097
if not self:
3098-
return negInf
3098+
return _negInf
30993099

31003100
# log10(Infinity) = Infinity
31013101
if self._isinfinity() == 1:
3102-
return Inf
3102+
return _Inf
31033103

31043104
# log10(negative or -Infinity) raises InvalidOperation
31053105
if self._sign == 1:
@@ -3151,7 +3151,7 @@ def logb(self, context=None):
31513151

31523152
# logb(+/-Inf) = +Inf
31533153
if self._isinfinity():
3154-
return Inf
3154+
return _Inf
31553155

31563156
# logb(0) = -Inf, DivisionByZero
31573157
if not self:
@@ -3308,7 +3308,7 @@ def next_minus(self, context=None):
33083308
return ans
33093309

33103310
if self._isinfinity() == -1:
3311-
return negInf
3311+
return _negInf
33123312
if self._isinfinity() == 1:
33133313
return _dec_from_triple(0, '9'*context.prec, context.Etop())
33143314

@@ -3331,7 +3331,7 @@ def next_plus(self, context=None):
33313331
return ans
33323332

33333333
if self._isinfinity() == 1:
3334-
return Inf
3334+
return _Inf
33353335
if self._isinfinity() == -1:
33363336
return _dec_from_triple(1, '9'*context.prec, context.Etop())
33373337

@@ -5572,15 +5572,15 @@ def _format_align(body, spec_dict):
55725572
##### Useful Constants (internal use only) ################################
55735573

55745574
# Reusable defaults
5575-
Inf = Decimal('Inf')
5576-
negInf = Decimal('-Inf')
5577-
NaN = Decimal('NaN')
5578-
Dec_0 = Decimal(0)
5579-
Dec_p1 = Decimal(1)
5580-
Dec_n1 = Decimal(-1)
5581-
5582-
# Infsign[sign] is infinity w/ that sign
5583-
Infsign = (Inf, negInf)
5575+
_Inf = Decimal('Inf')
5576+
_negInf = Decimal('-Inf')
5577+
_NaN = Decimal('NaN')
5578+
_Dec_0 = Decimal(0)
5579+
_Dec_p1 = Decimal(1)
5580+
_Dec_n1 = Decimal(-1)
5581+
5582+
# _Infsign[sign] is infinity w/ that sign
5583+
_Infsign = (_Inf, _negInf)
55845584

55855585

55865586

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ Core and Builtins
7878
Library
7979
-------
8080

81+
- Issue #4812: add missing underscore prefix to some internal-use-only
82+
constants in the decimal module. (Dec_0 becomes _Dec_0, etc.)
83+
8184
- Issue #4702: Throwing a DistutilsPlatformError instead of IOError in case
8285
no MSVC compiler is found under Windows. Original patch by Philip Jenvey.
8386

0 commit comments

Comments
 (0)