diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-06-01 21:05:48 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-01 21:05:48 (GMT) |
commit | bdbad71b9def0b86433de12cecca022eee91bd9f (patch) | |
tree | 147c8a3e08454a95e0e4900388d88f7b65430f63 /Lib/test/test_cmath.py | |
parent | 1a4d9ffa1aecd7e750195f2be06d3d16c7a3a88f (diff) | |
download | cpython-bdbad71b9def0b86433de12cecca022eee91bd9f.zip cpython-bdbad71b9def0b86433de12cecca022eee91bd9f.tar.gz cpython-bdbad71b9def0b86433de12cecca022eee91bd9f.tar.bz2 |
bpo-20092. Use __index__ in constructors of int, float and complex. (GH-13108)
Diffstat (limited to 'Lib/test/test_cmath.py')
-rw-r--r-- | Lib/test/test_cmath.py | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/Lib/test/test_cmath.py b/Lib/test/test_cmath.py index 43a074b..a00185f 100644 --- a/Lib/test/test_cmath.py +++ b/Lib/test/test_cmath.py @@ -220,12 +220,11 @@ class CMathTests(unittest.TestCase): pass class NeitherComplexNorFloatOS: pass - class MyInt(object): + class Index: def __int__(self): return 2 def __index__(self): return 2 - class MyIntOS: + class MyInt: def __int__(self): return 2 - def __index__(self): return 2 # other possible combinations of __float__ and __complex__ # that should work @@ -255,6 +254,7 @@ class CMathTests(unittest.TestCase): self.assertEqual(f(FloatAndComplexOS()), f(cx_arg)) self.assertEqual(f(JustFloat()), f(flt_arg)) self.assertEqual(f(JustFloatOS()), f(flt_arg)) + self.assertEqual(f(Index()), f(int(Index()))) # TypeError should be raised for classes not providing # either __complex__ or __float__, even if they provide # __int__ or __index__. An old-style class @@ -263,7 +263,6 @@ class CMathTests(unittest.TestCase): self.assertRaises(TypeError, f, NeitherComplexNorFloat()) self.assertRaises(TypeError, f, MyInt()) self.assertRaises(Exception, f, NeitherComplexNorFloatOS()) - self.assertRaises(Exception, f, MyIntOS()) # non-complex return value from __complex__ -> TypeError for bad_complex in non_complexes: self.assertRaises(TypeError, f, MyComplex(bad_complex)) |