mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-31293: Fix crashes in truediv and mul of a timedelta by a float with a bad as_integer_ratio() method. (#3227)
This commit is contained in:
parent
9974e1bcf3
commit
865e4b4f63
3 changed files with 55 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue