bpo-37999: No longer use __int__ in implicit integer conversions. (GH-15636)

Only __index__ should be used to make integer conversions lossless.
This commit is contained in:
Serhiy Storchaka 2020-05-26 18:43:38 +03:00 committed by GitHub
parent 8ad052464a
commit 578c3955e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
87 changed files with 226 additions and 2937 deletions

View file

@ -502,14 +502,10 @@ class MathTests(unittest.TestCase):
self.assertRaises(ValueError, math.factorial, -10**100)
def testFactorialNonIntegers(self):
with self.assertWarns(DeprecationWarning):
self.assertEqual(math.factorial(5.0), 120)
with self.assertWarns(DeprecationWarning):
self.assertRaises(ValueError, math.factorial, 5.2)
with self.assertWarns(DeprecationWarning):
self.assertRaises(ValueError, math.factorial, -1.0)
with self.assertWarns(DeprecationWarning):
self.assertRaises(ValueError, math.factorial, -1e100)
self.assertRaises(TypeError, math.factorial, 5.0)
self.assertRaises(TypeError, math.factorial, 5.2)
self.assertRaises(TypeError, math.factorial, -1.0)
self.assertRaises(TypeError, math.factorial, -1e100)
self.assertRaises(TypeError, math.factorial, decimal.Decimal('5'))
self.assertRaises(TypeError, math.factorial, decimal.Decimal('5.2'))
self.assertRaises(TypeError, math.factorial, "5")
@ -520,8 +516,7 @@ class MathTests(unittest.TestCase):
# Currently raises OverflowError for inputs that are too large
# to fit into a C long.
self.assertRaises(OverflowError, math.factorial, 10**100)
with self.assertWarns(DeprecationWarning):
self.assertRaises(OverflowError, math.factorial, 1e100)
self.assertRaises(TypeError, math.factorial, 1e100)
def testFloor(self):
self.assertRaises(TypeError, math.floor)