diff options
author | Stefan Krah <skrah@bytereef.org> | 2016-07-17 12:01:42 (GMT) |
---|---|---|
committer | Stefan Krah <skrah@bytereef.org> | 2016-07-17 12:01:42 (GMT) |
commit | 8c126f17f09eeb75d3d3c9737150384cd1dd9c03 (patch) | |
tree | deb229d3647b9950ffb59999ebc2fe0ddba772c7 /Lib/test/test_decimal.py | |
parent | 80ab069f1b040b7418833d9c1facf77ad2bd4363 (diff) | |
download | cpython-8c126f17f09eeb75d3d3c9737150384cd1dd9c03.zip cpython-8c126f17f09eeb75d3d3c9737150384cd1dd9c03.tar.gz cpython-8c126f17f09eeb75d3d3c9737150384cd1dd9c03.tar.bz2 |
Issue #26974: Fix segfault in the presence of absurd subclassing. Proactively
eliminate all internal uses of overridden methods.
Diffstat (limited to 'Lib/test/test_decimal.py')
-rw-r--r-- | Lib/test/test_decimal.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py index cde5d78..1aa0bf8 100644 --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -5398,6 +5398,34 @@ class CWhitebox(unittest.TestCase): y = Decimal(10**(9*25)).__sizeof__() self.assertEqual(y, x+4) + def test_internal_use_of_overridden_methods(self): + Decimal = C.Decimal + + # Unsound subtyping + class X(float): + def as_integer_ratio(self): + return 1 + def __abs__(self): + return self + + class Y(float): + def __abs__(self): + return [1]*200 + + class I(int): + def bit_length(self): + return [1]*200 + + class Z(float): + def as_integer_ratio(self): + return (I(1), I(1)) + def __abs__(self): + return self + + for cls in X, Y, Z: + self.assertEqual(Decimal.from_float(cls(101.1)), + Decimal.from_float(101.1)) + @requires_docstrings @unittest.skipUnless(C, "test requires C version") class SignatureTest(unittest.TestCase): |