mirror of
https://github.com/python/cpython.git
synced 2025-10-05 06:31:48 +00:00
[3.6] bpo-31293: Fix crashes in truediv and mul of a timedelta by a float with a bad as_integer_ratio() method. (GH-3227) (#3654)
(cherry picked from commit 865e4b4f63
)
This commit is contained in:
parent
99a51d4e5b
commit
f37dd11f0d
3 changed files with 55 additions and 4 deletions
|
@ -846,6 +846,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