summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorOren Milman <orenmn@gmail.com>2017-09-19 12:58:11 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-09-19 12:58:11 (GMT)
commit865e4b4f630e2ae91e61239258abb58b488f1d65 (patch)
tree3c3ae126a58e5a9e7dddef58d305fc6faafad54e /Lib
parent9974e1bcf3d0cec9b38b39b39b7ec8a1ebd9ef54 (diff)
downloadcpython-865e4b4f630e2ae91e61239258abb58b488f1d65.zip
cpython-865e4b4f630e2ae91e61239258abb58b488f1d65.tar.gz
cpython-865e4b4f630e2ae91e61239258abb58b488f1d65.tar.bz2
bpo-31293: Fix crashes in truediv and mul of a timedelta by a float with a bad as_integer_ratio() method. (#3227)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/datetimetester.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index 29b70e1..a042efd 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -866,6 +866,26 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
self.assertRaises(TypeError, divmod, t, 10)
+ def test_issue31293(self):
+ # The interpreter shouldn't crash in case a timedelta is divided or
+ # multiplied by a float with a bad as_integer_ratio() method.
+ def get_bad_float(bad_ratio):
+ class BadFloat(float):
+ def as_integer_ratio(self):
+ return bad_ratio
+ return BadFloat()
+
+ with self.assertRaises(TypeError):
+ timedelta() / get_bad_float(1 << 1000)
+ with self.assertRaises(TypeError):
+ timedelta() * get_bad_float(1 << 1000)
+
+ for bad_ratio in [(), (42, ), (1, 2, 3)]:
+ with self.assertRaises(ValueError):
+ timedelta() / get_bad_float(bad_ratio)
+ with self.assertRaises(ValueError):
+ timedelta() * get_bad_float(bad_ratio)
+
#############################################################################
# date tests