Commit abfedb4e authored by Stefan Krah's avatar Stefan Krah

Merge 3.3.

parents 21a0b07c f5c3134b
This diff is collapsed.
......@@ -2594,7 +2594,7 @@ class Decimal(object):
ans = ans._fix(context)
return ans
def same_quantum(self, other):
def same_quantum(self, other, context=None):
"""Return True if self and other have the same exponent; otherwise
return False.
......@@ -2912,7 +2912,7 @@ class Decimal(object):
except TypeError:
return 0
def canonical(self, context=None):
def canonical(self):
"""Returns the same Decimal object.
As we do not have different encodings for the same number, the
......@@ -2932,7 +2932,7 @@ class Decimal(object):
return ans
return self.compare(other, context=context)
def compare_total(self, other):
def compare_total(self, other, context=None):
"""Compares self to other using the abstract representations.
This is not like the standard compare, which use their numerical
......@@ -3005,7 +3005,7 @@ class Decimal(object):
return _Zero
def compare_total_mag(self, other):
def compare_total_mag(self, other, context=None):
"""Compares self to other using abstract repr., ignoring sign.
Like compare_total, but with operand's sign ignored and assumed to be 0.
......@@ -3027,7 +3027,7 @@ class Decimal(object):
else:
return _dec_from_triple(1, self._int, self._exp, self._is_special)
def copy_sign(self, other):
def copy_sign(self, other, context=None):
"""Returns self with the sign of other."""
other = _convert_other(other, raiseit=True)
return _dec_from_triple(other._sign, self._int,
......@@ -4180,7 +4180,7 @@ class Context(object):
"""
if not isinstance(a, Decimal):
raise TypeError("canonical requires a Decimal as an argument.")
return a.canonical(context=self)
return a.canonical()
def compare(self, a, b):
"""Compares values numerically.
......
This diff is collapsed.
......@@ -167,6 +167,10 @@ Core and Builtins
Library
-------
- Issue #15783: Except for the number methods, the C version of decimal now
supports all None default values present in decimal.py. These values were
largely undocumented.
- Issue #11175: argparse.FileType now accepts encoding and errors
arguments. Patch by Lucas Maystre.
......
This diff is collapsed.
This diff is collapsed.
......@@ -36,6 +36,7 @@ from copy import copy
from collections import defaultdict
from test.support import import_fresh_module
from randdec import randfloat, all_unary, all_binary, all_ternary
from randdec import unary_optarg, binary_optarg, ternary_optarg
from formathelper import rand_format, rand_locale
C = import_fresh_module('decimal', fresh=['_decimal'])
......@@ -834,6 +835,17 @@ def test_unary(method, prec, exp_range, restricted_range, itr, stat):
except VerifyError as err:
log(err)
if not method.startswith('__'):
for op in unary_optarg(prec, exp_range, itr):
t = TestSet(method, op)
try:
if not convert(t):
continue
callfuncs(t)
verify(t, stat)
except VerifyError as err:
log(err)
def test_binary(method, prec, exp_range, restricted_range, itr, stat):
"""Iterate a binary function through many test cases."""
if method in BinaryRestricted:
......@@ -848,6 +860,17 @@ def test_binary(method, prec, exp_range, restricted_range, itr, stat):
except VerifyError as err:
log(err)
if not method.startswith('__'):
for op in binary_optarg(prec, exp_range, itr):
t = TestSet(method, op)
try:
if not convert(t):
continue
callfuncs(t)
verify(t, stat)
except VerifyError as err:
log(err)
def test_ternary(method, prec, exp_range, restricted_range, itr, stat):
"""Iterate a ternary function through many test cases."""
if method in TernaryRestricted:
......@@ -862,6 +885,17 @@ def test_ternary(method, prec, exp_range, restricted_range, itr, stat):
except VerifyError as err:
log(err)
if not method.startswith('__'):
for op in ternary_optarg(prec, exp_range, itr):
t = TestSet(method, op)
try:
if not convert(t):
continue
callfuncs(t)
verify(t, stat)
except VerifyError as err:
log(err)
def test_format(method, prec, exp_range, restricted_range, itr, stat):
"""Iterate the __format__ method through many test cases."""
for op in all_unary(prec, exp_range, itr):
......
......@@ -527,6 +527,11 @@ def all_unary(prec, exp_range, itr):
for _ in range(100):
yield (randtuple(prec, exp_range),)
def unary_optarg(prec, exp_range, itr):
for _ in range(100):
yield randdec(prec, exp_range), None
yield randdec(prec, exp_range), None, None
def all_binary(prec, exp_range, itr):
for a, b in bin_close_to_pow10(prec, exp_range, itr):
yield a, b
......@@ -543,6 +548,11 @@ def all_binary(prec, exp_range, itr):
for _ in range(100):
yield randdec(prec, exp_range), randdec(prec, exp_range)
def binary_optarg(prec, exp_range, itr):
for _ in range(100):
yield randdec(prec, exp_range), randdec(prec, exp_range), None
yield randdec(prec, exp_range), randdec(prec, exp_range), None, None
def all_ternary(prec, exp_range, itr):
for a, b, c in tern_close_numbers(prec, exp_range, -exp_range, itr):
yield a, b, c
......@@ -557,3 +567,11 @@ def all_ternary(prec, exp_range, itr):
b = randdec(prec, 2*exp_range)
c = randdec(prec, 2*exp_range)
yield a, b, c
def ternary_optarg(prec, exp_range, itr):
for _ in range(100):
a = randdec(prec, 2*exp_range)
b = randdec(prec, 2*exp_range)
c = randdec(prec, 2*exp_range)
yield a, b, c, None
yield a, b, c, None, None
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment